Skip to content

Commit

Permalink
Update README.markdown
Browse files Browse the repository at this point in the history
Signed-off-by: Vinit Pandit <[email protected]>
  • Loading branch information
Vinit-Pandit authored Apr 24, 2024
1 parent 9c4cc95 commit ef108b0
Showing 1 changed file with 36 additions and 46 deletions.
82 changes: 36 additions & 46 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@ standards such as [JSON Schema](http://json-schema.org), [JSON
Pointer](https://www.rfc-editor.org/rfc/rfc6901),
[JSONL](https://jsonlines.org), and more.

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 document =
sourcemeta::jsontoolkit::parse(R"JSON({
"name": "John Doe",
"age": 20,
"address": "zxy"
})JSON");

// JSON pointer for the name property
const sourcemeta::jsontoolkit::Pointer name_pointer{"name"};
// A new JSON document for the name
const sourcemeta::jsontoolkit::JSON name_value{"Johnny Doe"};
// Updating the value of the name using JSON pointer
sourcemeta::jsontoolkit::set(document, name_pointer, name_value);
sourcemeta::jsontoolkit::prettify(document, std::cout);
std::cout<<"\n";

// The above program will print the following to standard output:
//output :
// {
// "address": "zxy_with_bar",
// "age": 21,
// "name": "xyz_with_foo"
// }
}
```

Documentation
-------------

Expand All @@ -23,50 +59,4 @@ 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 ef108b0

Please sign in to comment.