An open API service indexing awesome lists of open source software.

https://github.com/beached/parse_json

Serialize to/deserialize from json file and/or parse json file to a variant object
https://github.com/beached/parse_json

Last synced: 2 months ago
JSON representation

Serialize to/deserialize from json file and/or parse json file to a variant object

Awesome Lists containing this project

README

        

# Parse Json & json_link

This is mainly a serialization/deserialization library that allows your to easily use json as the transport medium.

```c++
#include
#include

#include

struct config_t : public daw::json::json_link {
int port;
std::string url_path;

config_t( ) : daw::json::json_link{}, port{8080}, url_path{"/"} {}

config_t( config_t const &other ) = default;
config_t( config_t &&other ) = default;
config_t &operator=( config_t const & ) = default;
config_t &operator=( config_t && ) = default;
~config_t( ) = default;

static void map_to_json( ) {
json_link_integer( "port", port );
json_link_string( "url_path", url_path );
}
};

int main( int argc, char **argv ) {
config_t config{};
if( argc > 1 ) {
config = daw::json::from_file( argv[1] );
} else {
std::string path = argv[0] + ".json";
daw::json::to_file( path );
}

return EXIT_SUCCESS;
}
```

As you can see, the requirement is to inherit from the json_link class with the current class as a template parameter. And then, use the appropriate json_link_... command to give it a name and a variable to link to within a static method called map_to_json( ).

The order of the object element names is sorted in lexigraphical order of the codepoints. This may or may not make sense depending on the situation