zserge / jsmn

Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket
MIT License
3.72k stars 783 forks source link

Btc/typos and more - clean up Makefile; add new example #124

Open drbitboy opened 6 years ago

drbitboy commented 6 years ago
Makefile

- Use make variables to define targets
- Remove test executables in [make clean]
- Make strict library libjsmn_strict.a and other products
- Give examples consistent names
  - simple => simple_example (no change)
  - jsondump => jsondump_example (instead of jsondump)

examples/jsmndump.c

- New example code
- Similar to jsondump
- Outputs JS-ish names for primitives, plus array lengths
drbitboy commented 6 years ago

Hi Serge,

The Makefile changes are mostly to make the different steps consistent (e.g. example/simple.c build to executable simple_example, but example/jsondump.c used to build to exectuable jsondump (not to jsondump_example).

I also added another example based on some work I am doing for the OSIRIS-REx spacecraft mission to asteroid (101955) Bennu, that dumps the JSON primitives, plus array lenghts, with Javascript-like names. It would be somewhat inefficient, but those primitives could be put into a tree (e.g. avltree) with the JS-like names as keys, and the tree then used as a way to access primitives in the JSON. So in some ways it is similar to examples/simple.c, where the program knows the structure of the JSON beforehand and needs a way to navigate. In structure the new example is very similar to examples/jsondump.c, although I cleaned up the code that reads the file, and added a way to pass a filename instead of using only STDIN; I fully admit that "cleaned up" is a subjective term, of course, and some may find my code style a bit too dense and/or confusing (e.g. putting assignments inside while and if expressions).

Thanks for the great package.

Feel free of course to edit or reject the example, or this entire pull request, if you feel it does not add anything to the package.