1#ifndef SIMDJSON_JSONPATHUTIL_H
2#define SIMDJSON_JSONPATHUTIL_H
4#include "simdjson/error.h"
6#include "simdjson/common_defs.h"
20simdjson_inline
error_code parse_json_pointer_array_index(std::string_view json_pointer,
22 size_t &token_length)
noexcept {
26 for (; token_length < json_pointer.length() && json_pointer[token_length] !=
'/';
28 uint8_t digit = uint8_t(json_pointer[token_length] -
'0');
34 if (token_length > 0 && json_pointer[0] ==
'0') {
38 (((std::numeric_limits<size_t>::max)() - digit) / 10)) {
41 array_index = array_index * 10 + digit;
45 if (token_length == 0) {
62 if (!json_path.empty() && json_path.front() ==
'$') {
65 if (i >= json_path.size() || (json_path[i] !=
'.' &&
66 json_path[i] !=
'[')) {
73 result.reserve(json_path.size() * 2);
75 while (i < json_path.length()) {
76 if (json_path[i] ==
'.') {
78 }
else if (json_path[i] ==
'[') {
81 while (i < json_path.length() && json_path[i] !=
']') {
82 if (json_path[i] ==
'~') {
84 }
else if (json_path[i] ==
'/') {
87 result += json_path[i];
91 if (i == json_path.length() || json_path[i] !=
']') {
95 if (json_path[i] ==
'~') {
97 }
else if (json_path[i] ==
'/') {
100 result += json_path[i];
109inline std::pair<std::string_view, std::string_view> get_next_key_and_json_path(std::string_view& json_path) {
110 std::string_view key;
112 if (json_path.empty()) {
113 return {key, json_path};
118 if (json_path.front() ==
'$') {
123 if (i < json_path.length() && json_path[i] ==
'.') {
125 size_t key_start = i;
127 while (i < json_path.length() && json_path[i] !=
'[' && json_path[i] !=
'.') {
131 key = json_path.substr(key_start, i - key_start);
132 }
else if ((i + 1 < json_path.size()) && json_path[i] ==
'[' &&
133 (json_path[i + 1] ==
'\'' || json_path[i + 1] ==
'"')) {
141 const char quote = json_path[i + 1];
143 const size_t key_start = i;
144 while (i < json_path.length() && json_path[i] != quote) {
147 if (i >= json_path.length() ||
148 i + 1 >= json_path.length() ||
149 json_path[i + 1] !=
']') {
150 return {key, json_path};
152 key = json_path.substr(key_start, i - key_start);
154 }
else if ((i+2 < json_path.size()) && json_path[i] ==
'[' && json_path[i+1] ==
'*' && json_path[i+2] ==
']') {
160 return std::make_pair(key, json_path.substr(i));
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
@ INCORRECT_TYPE
JSON element has a different type than user expected.
@ INDEX_OUT_OF_BOUNDS
JSON array index too large.
@ INVALID_JSON_POINTER
Invalid JSON pointer syntax.
std::string json_path_to_pointer_conversion(std::string_view json_path)
Converts JSONPath to JSON Pointer.