25

We have requirement of C/C++ Parser in my application. What application does is it calls rest webservice and takes output from service. If output is JSON , it should parse it and shows the result to end user.

Could you please recommend me good/best C/CPP JSON parser (according to you) so that I can use in my application?

When I search online, I am getting multiple JSON parsers. But I would like to know about the best.

Thanks in advance

6
  • 12
    Pileborg, C/C++ means either C parser or C++ Parser :) Commented Apr 7, 2016 at 9:22
  • 4
    If you're programming in C you can't use a C++ library, and if you program in C++ you should say so, it doesn't mean you can't use libraries with a C interface, but it does mean you can use libraries with a C++-only interface which widens your possibilities. Always please only say the language you actually use, as well as tag the question appropriately. Commented Apr 7, 2016 at 9:25
  • Anyway, it's a moot point since this question is off-topic anyway: "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." Please see "What topics can I ask about here?", as well as "What types of questions should I avoid asking?". Commented Apr 7, 2016 at 9:27
  • 5
    Why are all the useful questions here on stack overflow closed ? Commented Sep 6, 2019 at 7:10
  • 3
    It's great that everyone keeps killing questions like this on SO because they're off topic and then the search engines still show SO in all the top searches. Really useful for the programming community to have such a high profile site never provide answers. Commented Oct 14, 2020 at 14:50

3 Answers 3

30

Assuming you're happy with a C++ implementation of the parser, I've not had any issues with nlohmann/json; although there are faster libraries it has been fast enough for my requirements and has the advantages that:

  • It is very easy to integrate into your project (single header)
  • A clean and simple API without excessively verbose syntax
  • Good test coverage

The Github page linked above has a great overview so it's not worth me going into much more detail here.

For a comparison of libraries along multiple facets (not just performance) you could look here: miloyip/nativejson-benchmark

Sign up to request clarification or add additional context in comments.

Comments

5

We are happy with RapidJson, which is in use for AssetImporterLib for the GLTF-importer.

You can find a performance test here ( 100% is best ). Regarding to these examples RapiJson has won. Be never measured the performance on our own to this lib in special.

Comments

5

I highly recommend Cereal. It's a portable, easy to use serialization library for C++, that supports JSON, XML, plain text, and binary formats.

3 Comments

Cereal looks pretty slick! I'm just having a lot of trouble with their documentation. Someone opened an issue on their GitHub for a better deserialization example and their response before closing the issue was "We have [...] examples elsewhere in the documentation that show round trip serialization." Except they didn't leave a link anywhere to the example; that's not resolving an issue IMHO. I already have a JSON file that's being generated by another program. All I need is a deserializer. Something that works similar to Newtonsoft's JSON library would be preferable.
@aj.toulan in the years since I posted this answer, I've started using JsonCpp. It can be found at github.com/open-source-parsers/jsoncpp, and it has a very intuitive interface, using square bracket [] operators, that takes minutes to learn. You'd have to write your own serialization and deserialization code, but it handles all the parsing and formatting for you, and you can get up and running in a few minutes.
Does not seem to be working with ref classes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.