feat: add Std::Json — JSON parser and serializer
- JsonValue struct supporting null, bool, number, string, array, object - Json_Parse(s: String) -> JsonValue: recursive descent parser - Json_Stringify(v: JsonValue) -> String: recursive serializer - Access helpers: Json_ObjectGet, Json_ObjectSet, Json_ObjectHas, Json_ArrayGet, Json_ArrayPush, Json_ArrayLen, Json_ObjectLen - Constructors: Json_Null, Json_Bool, Json_Number, Json_String, Json_Array, Json_Object - Type accessors: Json_IsNull, Json_AsBool, Json_AsNumber, Json_AsString - examples/json.bux: demonstrates parse, access, build programmatically - Add os_time, process, json to test-examples suite
This commit is contained in:
@@ -0,0 +1 @@
|
||||
[Package]
|
||||
@@ -0,0 +1,22 @@
|
||||
import Std::Io::{PrintLine};
|
||||
import Std::Json;
|
||||
|
||||
func Main() -> int {
|
||||
let s: String = "{\"user\":{\"name\":\"Bux\",\"active\":true,\"score\":99.5,\"tags\":[\"fast\",\"safe\",null],\"meta\":{\"v\":1}}}";
|
||||
let j: JsonValue = Json_Parse(s);
|
||||
PrintLine(Json_Stringify(j));
|
||||
|
||||
let user: JsonValue = Json_ObjectGet(j, "user");
|
||||
PrintLine(Json_AsString(Json_ObjectGet(user, "name")));
|
||||
if Json_AsBool(Json_ObjectGet(user, "active")) {
|
||||
PrintLine("yes");
|
||||
} else {
|
||||
PrintLine("no");
|
||||
}
|
||||
|
||||
let tags: JsonValue = Json_ObjectGet(user, "tags");
|
||||
PrintLine(Json_AsString(Json_ArrayGet(tags, 0)));
|
||||
PrintLine(Json_AsString(Json_ArrayGet(tags, 1)));
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user