What is design pattern to store JSON objects in C++?

Viewed 168

A co-worker and I have been discussed the best way to store data in memory within our C++ server. Basically, we need to store all requisitions made by clients. Those requisitions come as JSONs objects, so each requisition may have different number of parameters. Later, clients can ask the server for a list of those requisitions.

The total number of requisitions is small (order of 10^3). Clients ask for the list of requisitions using pagination.

So my question is what is the standard way of doing that?

1) Create a class that stores every JSON and then, when requested, send the list of those JSONs.

2) Deserialize the JSON, store it in a class then serialize the data again when requested.

If 2, what is the best way of doing that in modern C++?

3) Another option?

Thank you.

1 Answers

If the client asks you to support JSON, the are only two steps you need to do:

  1. Add some JSON (e.g this) library with a suitable license to project.
  2. Use it.

If the implementation of JSON is not the main goal of the project, this should work.

Note: you can also get a lot of design hints inspecting the aforementioned repo.

Related