Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For json parsing, I really like JSMN (https://github.com/zserge/jsmn/). It doesn't allocate memory, has a simple and easy to use API, and is pretty fast.


I started out using JSMN for parsing JSON in our embedded devices at work, but the requirement to pre-allocate all the tokens turned out to be a problem - I was running out of memory when the configuration files got too large…

So I wrote a new parser that trades lower RAM usage for higher CPU usage: https://bitbucket.org/tlabwest/json-reader/overview

Sample usage:

  json_token_t json;
  json_validate(json_string, &json);
  
  json_token_t value;
  json_find(&json, "key1/subkey:2/value1", &value);
  
  char s[bufsize];
  json_decode_string(&value, s, bufsize);
  
  printf("%s\n", s);
  
  json_free(&json);


Its sadly not strict enough what it accepts, got a buffer overflow quite easily. So you probably shouldn't use it for user supplied data.


In terms of pure syntactic sugar/ease of use, it's hard to beat nlohmann/json: https://github.com/nlohmann/json

It may not be as fast as these other guys but it's sure as heck a lot more intuitive and convenient. For casual JSON usage cases, I've been recommending this library.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: