MCPcopy Create free account
hub / github.com/MariaDB/server / json_get_object_key_int

Function json_get_object_key_int

strings/json_lib.c:2159–2201  ·  view source on GitHub ↗

Simple json lookup for a value by the key. Expects JSON object. Only scans the 'first level' of the object, not the nested structures. @param js [in] json object to search in @param js_end [in] end of json string @param key [in] key to search for @param key_end [in] - " - @param value_start [out] pointer into js (value or c

Source from the content-addressed store, hash-verified

2157 @retval JSV_NOTHING - no such key found.
2158*/
2159enum json_types json_get_object_key_int(json_engine_t *je, const char *js,
2160 const char *js_end, const char *key,
2161 const char **value, int *value_len)
2162{
2163 const char *key_end= key + strlen(key);
2164 json_string_t key_name;
2165 int n_keys= 0;
2166
2167 json_string_set_cs(&key_name, &my_charset_utf8mb4_bin);
2168
2169 json_scan_start(je, &my_charset_utf8mb4_bin,(const uchar *) js,
2170 (const uchar *) js_end);
2171
2172 if (json_read_value(je) ||
2173 je->value_type != JSON_VALUE_OBJECT)
2174 goto err_return;
2175
2176 while (!json_scan_next(je))
2177 {
2178 switch (je->state)
2179 {
2180 case JST_KEY:
2181 n_keys++;
2182 json_string_set_str(&key_name, (const uchar *) key,
2183 (const uchar *) key_end);
2184 if (json_key_matches(je, &key_name))
2185 return smart_read_value(je, value, value_len);
2186
2187 if (json_skip_key(je))
2188 goto err_return;
2189
2190 break;
2191
2192 case JST_OBJ_END:
2193 *value= (const char *) (je->s.c_str - je->sav_c_len);
2194 *value_len= n_keys;
2195 return JSV_NOTHING;
2196 }
2197 }
2198
2199err_return:
2200 return JSV_BAD_JSON;
2201}
2202
2203enum json_types json_get_object_key(const char *js, const char *js_end,
2204 const char *key, const char **value,

Callers 1

json_get_object_keyFunction · 0.85

Calls 8

json_string_set_csFunction · 0.85
json_scan_startFunction · 0.85
json_read_valueFunction · 0.85
json_scan_nextFunction · 0.85
json_string_set_strFunction · 0.85
json_key_matchesFunction · 0.85
smart_read_valueFunction · 0.85
json_skip_keyFunction · 0.85

Tested by

no test coverage detected