Skip to content

Commit

Permalink
Update README.markdown
Browse files Browse the repository at this point in the history
Signed-off-by: Vinit Pandit <106718914+MeastroZI@users.noreply.github.com>
  • Loading branch information
Vinit-Pandit authored Apr 23, 2024
1 parent 8c62eab commit 6b5a81b
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sourcemeta/jsontoolkit/json.h>
#include <sourcemeta/jsontoolkit/jsonpointer.h>
#include <sstream>
#include <iostream>

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"
}

*/
}
```

0 comments on commit 6b5a81b

Please sign in to comment.