MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / from_json

Function from_json

subprojects/llama.cpp/common/jinja/value.cpp:1111–1141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1109
1110
1111static value from_json(const nlohmann::ordered_json & j, bool mark_input) {
1112 if (j.is_null()) {
1113 return mk_val<value_none>();
1114 } else if (j.is_boolean()) {
1115 return mk_val<value_bool>(j.get<bool>());
1116 } else if (j.is_number_integer()) {
1117 return mk_val<value_int>(j.get<int64_t>());
1118 } else if (j.is_number_float()) {
1119 return mk_val<value_float>(j.get<double>());
1120 } else if (j.is_string()) {
1121 auto str = mk_val<value_string>(j.get<std::string>());
1122 if (mark_input) {
1123 str->mark_input();
1124 }
1125 return str;
1126 } else if (j.is_array()) {
1127 auto arr = mk_val<value_array>();
1128 for (const auto & item : j) {
1129 arr->push_back(from_json(item, mark_input));
1130 }
1131 return arr;
1132 } else if (j.is_object()) {
1133 auto obj = mk_val<value_object>();
1134 for (auto it = j.begin(); it != j.end(); ++it) {
1135 obj->insert(it.key(), from_json(it.value(), mark_input));
1136 }
1137 return obj;
1138 } else {
1139 throw std::runtime_error("Unsupported JSON value type");
1140 }
1141}
1142
1143// compare operator for value_t
1144bool value_compare(const value & a, const value & b, value_compare_op op) {

Callers 3

test_json_serializationFunction · 0.85
loadMethod · 0.85
global_from_jsonFunction · 0.85

Calls 7

mark_inputMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
keyMethod · 0.45
valueMethod · 0.45

Tested by 1

test_json_serializationFunction · 0.68