1

I need to model a JSon in C++. Firstly I thought about:

boost::property_tree

But unfortunately - it does not care about JSon types. Integers are represented as strings - and it is not an option.

The second idea would be:

boost::variant with recursive_wrapper

Which looks quite promising.

What kind of approach could you recommend? Do you know better approaches? It looks like a common problem, so there have to be a lot of well tested solutions.

I'm unfamiliar with C++ JSon libraries. If you could recommend any - I would be grateful as well.

Dejwi
  • 4,393
  • 12
  • 45
  • 74
  • 4
    What about using json libraries?.. –  Oct 01 '15 at 07:33
  • Are you sure? In boost::property_tree page I can read "In addition, the library provides parsers and generators for a number of data formats that can be represented by such a tree, including XML, INI, and JSON." – Jepessen Oct 01 '15 at 07:54
  • You may also consider using Qt's QJson framework which is pretty good. – Marco Oct 01 '15 at 08:20
  • @Marco I would be glad to use Qt, unfortunately I cannot due to licensing issues, – Dejwi Oct 01 '15 at 09:04
  • @Dejwi I am sure you know what you are doing, but just in case you missed it Qt licensing has many options including LGPL – Marco Oct 01 '15 at 09:20

1 Answers1

2

For JSon you typically want to take a library. You could ofcourse write your own implementation (parser etc.) but I don't see why you would do that considering there are so many good ones freely available.

Some examples:

Floris Velleman
  • 4,848
  • 4
  • 29
  • 46
  • 2
    Try https://github.com/nlohmann/json It is a header only library and pretty simple to use and provides most necessary functionalities. – Pooja Nilangekar Oct 01 '15 at 07:42
  • 1
    boost::spirit + boost::variant = json_spirit http://www.codeproject.com/Articles/20027/JSON-Spirit-A-C-JSON-Parser-Generator-Implemented – Richard Hodges Oct 23 '15 at 21:05