MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / from_json

Method from_json

include/chaiscript/utility/json_wrap.hpp:24–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22 private:
23
24 static Boxed_Value from_json(const json::JSON &t_json)
25 {
26 switch( t_json.JSONType() ) {
27 case json::JSON::Class::Null:
28 return Boxed_Value();
29 case json::JSON::Class::Object:
30 {
31 std::map<std::string, Boxed_Value> m;
32
33 for (const auto &p : t_json.object_range())
34 {
35 m.insert(std::make_pair(p.first, from_json(p.second)));
36 }
37
38 return Boxed_Value(m);
39 }
40 case json::JSON::Class::Array:
41 {
42 std::vector<Boxed_Value> vec;
43
44 for (const auto &p : t_json.array_range())
45 {
46 vec.emplace_back(from_json(p));
47 }
48
49 return Boxed_Value(vec);
50 }
51 case json::JSON::Class::String:
52 return Boxed_Value(t_json.to_string());
53 case json::JSON::Class::Floating:
54 return Boxed_Value(t_json.to_float());
55 case json::JSON::Class::Integral:
56 return Boxed_Value(t_json.to_int());
57 case json::JSON::Class::Boolean:
58 return Boxed_Value(t_json.to_bool());
59 }
60
61 throw std::runtime_error("Unknown JSON type");
62 }
63
64 static Boxed_Value from_json(const std::string &t_json)
65 {

Callers

nothing calls this directly

Calls 8

JSONTypeMethod · 0.80
object_rangeMethod · 0.80
array_rangeMethod · 0.80
to_floatMethod · 0.80
to_intMethod · 0.80
to_boolMethod · 0.80
Boxed_ValueClass · 0.50
to_stringMethod · 0.45

Tested by

no test coverage detected