json.hpp | A tiny C JSON parsing library using Boost.Spirit | JSON Processing library
kandi X-RAY | json.hpp Summary
kandi X-RAY | json.hpp Summary
json.hpp is a tiny (less than 100 lines of code) C++ JSON parsing library using Boost.Spirit for parsing, and Boost.Variant for the data structure. It works seamlessly with mstch, a {{mustache}} template library.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of json.hpp
json.hpp Key Features
json.hpp Examples and Code Snippets
#include
#include
int main() {
using boost::get;
std::string json_string{
"{\"names\": ["
" {\"name\": \"Chris\"},"
" {\"name\": \"Mark\"},"
" {\"name\": \"Scott\"}"
"]}"};
auto data = json::parse(json_string);
f
$ mkdir build
$ cd build
$ cmake ..
$ make test
using map = std::map;
using array = std::vector;
Community Discussions
Trending Discussions on json.hpp
QUESTION
I am trying to iterate over an array in a json file to retrieve an entry with an ID. The value that I want to compare it to is not a string (the json default type), but an uint64_t. For testing purposes, I wrote this simplified example:
...ANSWER
Answered 2021-Jun-01 at 17:47What version are you using? Because I got next output on latest version:
QUESTION
I'm using yaml-cpp
from conan center, in my conan file, yaml-cpp/0.6.3
, along with other dependencies.
The rest of the libraries link properly, so there must be something missing in my CMakeLists.txt
file. (Maybe some extra definition...?)
Until now, with those lines:
...ANSWER
Answered 2021-May-17 at 18:59The package is okay, but your profile is misconfigured.
undefined reference to `YAML::LoadFile(std::__cxx11::basic_string const&)' collect2: error: ld returned 1 exit status
You have to update your libcxx setting:
QUESTION
I have a very simple bazel project where I'm trying to add https://github.com/nlohmann/json as a dependency. To accomplish that, I cloned the json
repo locally and added a BUILD
file in the repo's root dir to generate a cc_library
containing the single include json.hpp
file. But when I build that, it always complains that there is nothing to build.
ANSWER
Answered 2021-Apr-27 at 04:12The problem is cc_library
has no DefaultInfo.files
, so when you specify its target on the command line Bazel doesn't know what things to build. Try bazel build :main
to build your binary instead.
Also, cc_library
itself does have output groups. Try something like bazel build :json --output_groups=dynamic_library
to get the library resulting from building its source files.
Note that in general, you should create a cc_binary
for any outputs from your build. Even if you want a shared object, create a cc_binary
with a name ending in .so
instead of using cc_library
alone. The dynamic_library
output doesn't handle transitive dependencies (although I guess that doesn't really matter for this library, which has no dependencies anyways).
QUESTION
I'm trying to call a function with parameters extracted from a JSON file using the nlohmann/json library.
I need to convert the JSON array retrieved from the JSON file to a tuple to call the function with.
The problem is that there's no build-up solution to convert nlohmann::basic_json<> to std::tuple in c++
the source code with comments to explain much more the programming issue :
...ANSWER
Answered 2021-Apr-19 at 14:06Let's assume that you only pass non-overloaded functions, function pointers, or function objects with one operator()
. Lets also assume that the json
object is always an array of parameters.
First we need to make a tuple from the json and the target arguments
QUESTION
I have a class where I want to have a function that uses nlohmann::json& as the argument:
...ANSWER
Answered 2021-Apr-07 at 00:15If we have a look at the source, we can see that json
is defined in json_fwd.hpp.
QUESTION
I'm using nlohmann-json
on my C++ project on Visual Studio and I caught an error of
ANSWER
Answered 2021-Mar-31 at 07:32nlohmann json only supports creating arrays from c++ standard library containers. It wouldn't be possible to create an array from a pointer as it has no information about the size of the array.
If you have c++20 then you can use std::span
to convert your pointer (and a size) into a container:
QUESTION
I'm new to CMake and have the following problem (reduced to a MWE):
Given is the project structure
...ANSWER
Answered 2021-Mar-07 at 14:05You have to add 'nlohmann_json' as link target for your static lib:
QUESTION
I want to have all the values of a specific field in my mongodb using mongocxx. I have 100 documents in my collection and each having a field "X1_position", the values of this field is float. I want to get all the 100 values of that field and want to store it into an array. I am using following code, but it is not working
...ANSWER
Answered 2021-Feb-12 at 20:54I think that what you're after is projection. You don't need to filter since you said you want all docs, but you need to tell MongoDB which fields you want back:
QUESTION
I'm using nlohmann::json to (de)serialize some C++ objects in JSON. I haven't yet understood how to set up the code to work with a third-party library (SoapySDR). My code is in the global namespace in this example, while the SoapySDR code is in its own namespace. I'm getting a ton of compile errors with this simplified example:
...ANSWER
Answered 2020-Oct-16 at 19:54The to_json
and from_json
overloads for your data types need to be in the type's namespace for the library to find them:
QUESTION
Hi Stack Overflow Community !
I am working on a project that heavily uses the interesting nlohmann_json
library and it appears that I need to add an inheritance link on a specific class, which objects are serialized at one moment.
I tried different advice found on the github Issues page of the library, but can't make it work.
Here is an dummy code I tried :
...ANSWER
Answered 2020-Oct-14 at 12:40nlohmann.json does not include polymorphic serializing, but you can implement it yourself in a specialized adl_serializer
. Here we're storing and checking an additional _type
JSON field, used as a key to map to pairs of type-erased from/to functions for each derived type.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install json.hpp
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page