json.nx
buildroot/runtime/json.nx
about
json.nx -- pull-style JSON parser (Phase G12, RFC 8259).
Research / reference:
RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format
Crockford 2002 — json.org, the original spec
Design: pull-style / event-driven parser. The caller invokes
json_next(p) in a loop; each call emits one event:
JSON_NULL / JSON_BOOL / JSON_INT / JSON_STRING
JSON_ARRAY_BEGIN / JSON_ARRAY_END
JSON_OBJECT_BEGIN / JSON_OBJECT_END
JSON_KEY (for object member names)
JSON_END (end of input)
JSON_ERROR (malformed input)
Zero heap allocation per event. String values are returned as
(start, len) slices into the original input buffer; the caller
copies if they need persistence.
Scope: RFC 8259 compliant for well-formed input. Skips whitespace
per spec, supports \" \\ \/ \b \f \n \r \t escape sequences in
strings. Number parsing handles integers; \uXXXX unicode escapes
and fractional numbers deferred to a follow-up.
dependencies 1 imports · 1 importers
imports: syscalls.nx
imported by: _api_extract.nx
structs
| 40 | struct JsonParser { |
consts
| 28 | const JSON_END: i64 = 0 |
| 29 | const JSON_NULL: i64 = 1 |
| 30 | const JSON_BOOL: i64 = 2 |
| 31 | const JSON_INT: i64 = 3 |
| 32 | const JSON_STRING: i64 = 4 |
| 33 | const JSON_ARRAY_BEGIN: i64 = 5 |
| 34 | const JSON_ARRAY_END: i64 = 6 |
| 35 | const JSON_OBJECT_BEGIN: i64 = 7 |
| 36 | const JSON_OBJECT_END: i64 = 8 |
| 37 | const JSON_KEY: i64 = 9 |
| 38 | const JSON_ERROR: i64 = 10 |
functions
| 53 | func json_new(src: *u8, len: i64) -> *JsonParser {
called by 1: main |
| 64 | func json_skip_ws(p: *JsonParser) -> i64 {
called by 1: json_next |
| 83 | func json_peek(p: *JsonParser) -> i64 {
called by 1: json_next |
| 91 | func json_read_string(p: *JsonParser) -> i64 {
called by 1: json_next |
| 117 | func json_read_int(p: *JsonParser) -> i64 {
called by 1: json_next |
| 141 | func json_skip_digits(p: *JsonParser) -> i64 {
called by 1: json_skip_frac |
| 156 | func json_skip_frac(p: *JsonParser) -> i64 { |
| 174 | func json_match(p: *JsonParser, word: *u8, len: i64) -> i64 {
called by 1: json_next |
| 187 | func json_next(p: *JsonParser) -> i64 {
called by 2: mainjson_next calls 7: json_skip_wsjson_nextjson_read_stringjson_peekjson_matchjson_read_int+1 |