Replace Variant with JSON #300
Labels
c++
Involves touching c++ code
documentation
Involves touching documentation
enhancement
tests
Involves touching tests
Feature Request
Describe the new feature:
So far, we have implemented our own
flit::Variant
type that can take on different types of values. This has proven to be difficult to add new types and time consuming to develop and test. Now that we have it, it is stable and works well.We see that many of the goals and types supported by
flit::Variant
are also supported by JSON. The JSON type is quite standard and found everywhere. It may be good to move to having JSON be our backend type to add more flexibility and stability. With a JSON type, you can have dictionaries, lists, and compose them in each other seamlessly. This would add significant capabilities to the use of FLiT.Suggested change:
I propose that we specifically use this implementation of JSON in C++:
https://github.com/nlohmann/json
for the following reasons:
json.hpp
fileIt may not be the fastest implementation of JSON in C++, but ease of use and a single file that can be copied into the FLiT repository are enticing.
We could incorporate a JSON library in the following ways:
json
objects to be another type stored inside offlit::Variant
*.dat
filesflit::Variant
to usejson
as its backend implementation*.dat
output filesjson.hpp
could be modified to allow long double typesflit::Variant
withjson
to be returned from flit testsjson.hpp
could be modified to allow long double typesNote: This library is under the MIT license. I recommend moving to a
3rdparty
directory along withtinydir.h
. Since we would only copy over the single header file (of 22,000 lines of code), we would not need to copy over the LICENSE file since it has the license declaration at the beginning of the file.Alternative approaches:
One thing we could do is implement our own JSON parser and output. We would be able to customize the output to also support long double and float.
Besides making our own implementation, there are many other JSON libraries out there for use by C++. Here are some choices:
libjson-c-dev
.libjsoncpp-dev
.libyajl-dev
libjansson-dev
.rapidjson-dev
.This would add another external dependency rather than just a single header file pulled in.
If speed is considered, here is a benchmark to compare 41 different implementations. It seems
rapidjson
is one of the fastest with a large conformance (significantly faster than others).The text was updated successfully, but these errors were encountered: