Closed markfink closed 5 years ago
https://gist.github.com/pt300/17441e85594428f7e2cb2a58cef2540d Here's an example that hopefully helps you.
@pt300 thank you for this code. Your code implements one big parser which regretably is exactly what I try to avoid. Instead of using a monolithic parser I am looking for a way to decompose into simpler sub-parsers. In other words I try to build a parser which is "assembled" / composed from multiple specialized parsers.
It's possible to split the parsing of house and car into separate parsing functions, but you still will need a parser for the root object which will call these "subparsers" when it encounters the appropriate keys. I could try writing something like that if you still need it.
right, it is possible. I hope smb. will share how they usually go about it. you know, a JSON file usually gets pretty big (often with hundreds or even thousands of elements) - I am still convinced that a suitable parser would not be engineed as a monolith. Unless the parser code is automatically generated from - lets say json-schema - which I think would be ok, too.
@pt300 again thank you for your help to discuss this. the solution to structure the parser into multiple functions was actually pretty simple. Today I figured it out and wrote a blog post about it (containing a complete sample).
please appologise if this is a "stupid" question... I am new to jsmn and so far I have only found simple examples on how to use it. I try to build a parser which is "assembled" from multiple specialized parsers.
For a data structure like this (always arrives as this big chunk of data) I like to split the parser into a house_parser() and car_parser().
I hope you can share some pointers on how to achieve this. Just a pointer to a sample or codebase which is doing this would be great! Thank you.