nx_json_v1.nx
buildroot/runtime/nx_json_v1.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 · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
structs
| 46 | struct JsonParser |
consts
| 34 | const JSON_END: i64 = 0 |
| 35 | const JSON_NULL: i64 = 1 |
| 36 | const JSON_BOOL: i64 = 2 |
| 37 | const JSON_INT: i64 = 3 |
| 38 | const JSON_STRING: i64 = 4 |
| 39 | const JSON_ARRAY_BEGIN: i64 = 5 |
| 40 | const JSON_ARRAY_END: i64 = 6 |
| 41 | const JSON_OBJECT_BEGIN: i64 = 7 |
| 42 | const JSON_OBJECT_END: i64 = 8 |
| 43 | const JSON_KEY: i64 = 9 |
| 44 | const JSON_ERROR: i64 = 10 |
functions
| 59 | func json_new(src: *u8, len: i64) -> *JsonParser calls 1: sys_mmap |
| 70 | func json_skip_ws(p: *JsonParser) -> i64 called by 1: json_next |
| 89 | func json_peek(p: *JsonParser) -> i64 called by 1: json_next |
| 97 | func json_read_string(p: *JsonParser) -> i64 called by 1: json_next |
| 123 | func json_read_int(p: *JsonParser) -> i64 called by 1: json_next |
| 152 | func json_match(p: *JsonParser, word: *u8, len: i64) -> i64 called by 1: json_next |
| 165 | func json_next(p: *JsonParser) -> i64 called by 1: json_next calls 6: json_skip_wsjson_nextjson_read_stringjson_peekjson_matchjson_read_int |