Skip to content
/ json2cpp Public
forked from lefticus/json2cpp

Compiles JSON into static constexpr C++ data structures with nlohmann::json API

License

Notifications You must be signed in to change notification settings

reg31/json2cpp

 
 

Repository files navigation

json2cpp

CI codecov Language grade: C++

json2cpp compiles a json file into static constexpr data structures that can be used at compile time or runtime.

Features

  • Literally 0 runtime overhead for loading the statically compiled JSON resource
  • Fully constexpr capable if you want to make compile-time decisions based on the JSON resource file
  • A .cpp firewall file is provided for you, if you have a large resource and don't want to pay the cost of compiling it more than once (but for normal size files it is VERY fast to compile, they are just data structures)
  • nlohmann::json compatible API (should be a drop-in replacement, some features might still be missing)
  • valijson adapter file provided

See the test folder for examples for building resources, using the valijson adapter, constexpr usage of resources, and firewalled usage of resources.

This is a fork of the amazing json2cpp with the following changes:

Usage

Have your json file in the same folder as the json2cpp executable and tpye the command:

json2cpp "outputCppClassName" "yourJsonFile.json" "outputFolderPath/baseFilename"

I advise outputCppClassName and baseFilename to be the same for consistency, e.g.:

json2cpp "myClass" "myFile.json" "./myClass"

This will generate 3 files you can include in your project: myClass.cpp myClass.hpp myClass_impl.cpp

utf16 support

Set #DEFINE JSON2CPP_USE_UTF16 in your project to compile as utf16 string views (char16_t) instead of utf8, this allows implicit conversion to QStringView or even to build a QString.

About

Compiles JSON into static constexpr C++ data structures with nlohmann::json API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CMake 51.0%
  • C++ 45.4%
  • Dockerfile 3.6%