This is a json parser in Jai. Tested in beta 0.2.025
There is a breaking change in the parser, where the result or success bool is returned as the first value, which is encouraged in Jai.
I was trying to do some lsp work for fun, and decided to write my own json parser.
- Support pointer.
- Support built-in Hash_Table
- Support built-in Tagged union (introduced in 0.2.023, not the module one)
Hash_Table support is a nightmare to deal with. Serializing Json into Jai Hash_Table is very hard. I created a Dumb_Table module just for dealing with that. I am not sure whether the Dumb_Table thing worth its separate module. A lot of pointer work is needed. Currently, only Hash_Table with string as Key_Type is supported.
There are a few functions you may want to use.
result, json := parse_json(s);
// or a helper function to read directly from file
result, json := parse_json_from_file(file_path);
// Print the json
formatted_json_string := json_print(json);
apple: Fruit;
ok, j := to_json(*apple);
result = from_json(json, *apple);
For more, you may look into examples.