MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / create_some_json

Function create_some_json

examples/src/json_cursor_examples.cpp:29–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27
28// Create some JSON (push)
29void create_some_json()
30{
31 std::ofstream os("./output/book_catalog.json",
32 std::ios_base::out | std::ios_base::trunc);
33 assert(os);
34
35 compact_json_stream_encoder encoder(os); // no indent
36
37 encoder.begin_array();
38 encoder.begin_object();
39 encoder.key("author");
40 encoder.string_value("Haruki Murakami");
41 encoder.key("title");
42 encoder.string_value("Hard-Boiled Wonderland and the End of the World");
43 encoder.key("price");
44 encoder.double_value(18.9);
45 encoder.end_object();
46 encoder.begin_object();
47 encoder.key("author");
48 encoder.string_value("Graham Greene");
49 encoder.key("title");
50 encoder.string_value("The Comedians");
51 encoder.key("price");
52 encoder.double_value(15.74);
53 encoder.end_object();
54 encoder.end_array();
55 encoder.flush();
56
57 os.close();
58
59 // Read the JSON and write it prettified to std::cout
60 json_stream_encoder writer(std::cout); // indent
61
62 std::ifstream is("./output/book_catalog.json");
63 assert(is);
64
65 json_stream_reader reader(is, writer);
66 reader.read();
67 std::cout << "\n\n";
68}
69
70// Read some JSON (pull)
71

Callers 1

mainFunction · 0.85

Calls 9

begin_arrayMethod · 0.45
begin_objectMethod · 0.45
keyMethod · 0.45
string_valueMethod · 0.45
double_valueMethod · 0.45
end_objectMethod · 0.45
end_arrayMethod · 0.45
flushMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected