This a json library for IoLanguage.
First, you should clone the repository in your project directory.
git submodule add https://github.com/LittleJianCH/IoJSON
Then you can use IoJSON in your project by doFile
doFile(the_path_to_json_io)
// e.g. doFile("./IoJSON/json.io")
There're two ways to use read a json file.
json1 := JSON clone readFromFile("./example.json")
json2 := JSON clone readFromString("{\"name\":\"littlejian\",\"age\":18, \"hobbies\":[\"code\",\"play\",\"drink\"]}")
As JSON
is inherited from Map
, you can use it like a Map
.
json2 at("name") println
json2 at("hobbies") foreach(hobby,
hobby println
)
json2 foreach(key, value,
key println
value println
)
json2 atPut("height", 180)
You can also use stringfy
to convert a JSON
to a String
.
json2 stringfy println
If you want to know more about IoJSON, here's a blog about it: https://littlejianch.github.io/let-s-implment-a-json-lib-in-io-by-metaprogramming/