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
- Host: GitHub
- URL: https://github.com/beached/parse_json
- Owner: beached
- License: bsl-1.0
- Created: 2016-05-05T23:22:47.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-05-28T04:59:25.000Z (almost 3 years ago)
- Last Synced: 2025-01-07T21:12:31.816Z (4 months ago)
- Language: C++
- Size: 445 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
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