3

I am considering to use JSON files as input files for a c++ program. I was told JSON files are a very safe and convenient way to input data. However, I do not have any experience with javascript. I would like to ask for recommendations on a good parser to use in order to start trying JSON files in a new project.

2

you may want to take a look at Json.hpp JSON library of jtc tool:

  • it's an easy C++14 API, featuring DSL-like style for building JSON programmatically
  • no dependancies, uses STL only
  • written in idiomatic c++14 style, cross platform, thread safe, extensively debuggable
  • features fast and powerful walk interface and iterators (easy to walk even irregular JSONs)
  • caters user callbacks (hooks to be placed on labels and iterators)
  • speed optimized when searching/walking very large JSONs (built-in search cache)
  • 2
    Welcome aboard, Dmitry. This is an excellent first post, and I have upvoted it. However, we prefer that you disclose your activity in anything which you recommend. In this case, you appear to be the author. Thant's not so bad because your code is FOSS, but sometimes people try to recommend things they sell. Even for FOSS it helps to know that the author is active and likely to help. Once again, welcome aboard :-) – Mawg Nov 13 '18 at 10:32
  • 1
    Got it. Will do. jtc tool of mine (as well as all the included libraries) will be maintained. They all are published under MIT license. Plus I'm open for any reasonable enhancement requests. – Dmitry L. Nov 14 '18 at 12:08
  • I look forward to seeing you be active on the site :-) – Mawg Nov 14 '18 at 12:44
1

I suggest you using, if you already didn't know them, Boost C++ libraries.

And for your actual scenario using the property_tree one.

For example a JSON like that:

{
   "menu":
   {
      "foo": true,
      "bar": "true",
      "value": 102.3E+06,
      "popup":
      [
         {"value": "New", "onclick": "CreateNewDoc()"},
         {"value": "Open", "onclick": "OpenDoc()"},
      ]
   }
}

Will be mapped in a tree like that:

menu
{
   foo true
   bar true
   value 102.3E+06
   popup
   {
      ""
      {
         value New
         onclick CreateNewDoc()
      }
      ""
      {
         value Open
         onclick OpenDoc()
      }
   }
}

On stackoverflow you can find many examples like that.

0

I mainly used the RapidJSON library.
So far I was quite satisfied with it and the documentation is also quite good.

Although I still want to try out this library. But up to now I had no time to compare them or do some benchmarks. So there is not much I can say about it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.