Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/petabyt/json
C JSON parser, no malloc, 200 lines
https://github.com/petabyt/json
Last synced: about 24 hours ago
JSON representation
C JSON parser, no malloc, 200 lines
- Host: GitHub
- URL: https://github.com/petabyt/json
- Owner: petabyt
- Created: 2024-01-04T02:07:49.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-05T05:17:33.000Z (2 months ago)
- Last Synced: 2025-01-12T22:15:03.246Z (6 days ago)
- Language: C
- Size: 21.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# json
~200LoC. It has one function:
```
int json_get(struct Parse *p, char *text, char *intent);
```
The output of the JS-like 'intent' will be stored in `p.str` with length `p.str_len`. This will just point to an offset in the buffer you gave the parser.
Optionally, you can call `char *json_fixup_string(struct Parse *p)` to get a formatted output.
```
char *data = ... see c.txt ...;
struct Parse p;
json_get(&p, data, "['amendments'][10]");
```Advantages:
- Very fast lexer & recursive descent parser
- Simple API
- No memory allocation required
- Correct (?) It parsed the entire [bible](https://github.com/heb12/gratis.json/blob/master/en/web.json).Disadvantages:
- May not throw error on invalid syntax / invalid accesses
- Not memory safe
- Doesn't parse into a tree for reformatting back to text