| 1109 | |
| 1110 | |
| 1111 | static 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 |
| 1144 | bool value_compare(const value & a, const value & b, value_compare_op op) { |