diff --git a/README.markdown b/README.markdown index 5e2545d0e..b59ad0577 100644 --- a/README.markdown +++ b/README.markdown @@ -22,3 +22,51 @@ long the outcome is distributed under the same license. Otherwise, you must obtain a [commercial license](./LICENSE-COMMERCIAL) that removes such restrictions. Read more about our licensing approach [here](https://www.sourcemeta.com/licensing/). + +Example +-------------- + +```cpp +#include +#include +#include +#include + +int main() +{ + // creating json using parse + sourcemeta::jsontoolkit::JSON _template_ = + sourcemeta::jsontoolkit::parse(R"JSON({ + "name" : "xyz" , + "age" : 20 , + "address" : "zxy" + })JSON"); + + // stringstream for output + std::ostringstream stringvar; + // pointer for the name + const sourcemeta::jsontoolkit::Pointer name_pointer{"name"}; + const sourcemeta::jsontoolkit::Pointer age_pointer{"age"}; + const sourcemeta::jsontoolkit::Pointer address_pointer{"address"}; + // value instance for json + const sourcemeta::jsontoolkit::JSON name_value{"xyz_with_foo"}; + const sourcemeta::jsontoolkit::JSON age_value{20 + 1}; + const sourcemeta::jsontoolkit::JSON address_value{"zxy_with_bar"}; + // updating the value of the name using pointer + sourcemeta::jsontoolkit::set(_template_, name_pointer, name_value); + sourcemeta::jsontoolkit::set(_template_, age_pointer, age_value); + sourcemeta::jsontoolkit::set(_template_, address_pointer, address_value); + sourcemeta::jsontoolkit::prettify(_template_, stringvar); + std::cout << stringvar.str() << std::endl; + + /* + output : + { + "address": "zxy_with_bar", + "age": 21, + "name": "xyz_with_foo" + } + + */ +} +```