Improve support for JSON casts
See original GitHub issueCurrently, casting to and from std::json
is supported only for scalar types. This proposes to extend JSON casting support to collection types as well as allowing to cast objects to std::json
.
New rules:
-
<json>Object
returns ajson
value containing the output representation of the object. That is, the result is the same asSELECT Object
in JSON mode, including the type shape. -
Scalar casts now work only for scalar JSON values, so casting a non-scalar JSON value to
std::str
is an error, and<json>'{"foo":"bar"}'
returns a JSON string ("{\"foo\":\"bar\"}"
), not a JSON object. -
Non-scalar string-to-JSON and JSON-to-string casting is accomplished by the new
str_to_json(str) -> json
andjson_to_str(json) -> str
functions correspondingly. -
<json>array_value
returns a JSON array -
<array<type>>json_value
returns an EdgeQL array of the given type.null
values in input produce an error (if the target type is notjson
, usejson_array_unpack
for fine-grained casting). -
<json>tuple_value
returns a JSON array and conversely<tuple<...>>json_value
converts a JSON array into a tuple.null
elements in input produce an error (if the target element type is notjson
). -
<json>named_tuple_value
returns a JSON object and conversely<tuple<name: type...>>json_value
converts a JSON object/array into a named tuple.null
values in input produce an error (if the target type is notjson
).
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
I think this is done
Remaining work items in this issue:
json
toanyenum
and vice versa (should be similar to thestd::str
cast inenumoperators.edgeql
)json
totuple
typesjson
toarray
types