question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve support for JSON casts

See original GitHub issue

Currently, 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:

  1. <json>Object returns a json value containing the output representation of the object. That is, the result is the same as SELECT Object in JSON mode, including the type shape.

  2. 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.

  3. Non-scalar string-to-JSON and JSON-to-string casting is accomplished by the new str_to_json(str) -> json and json_to_str(json) -> str functions correspondingly.

  4. <json>array_value returns a JSON array

  5. <array<type>>json_value returns an EdgeQL array of the given type. null values in input produce an error (if the target type is not json, use json_array_unpack for fine-grained casting).

  6. <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 not json).

  7. <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 not json).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
msullivancommented, Jul 24, 2020

I think this is done

0reactions
elpranscommented, Jul 24, 2020

Remaining work items in this issue:

  • allow casting json to anyenum and vice versa (should be similar to the std::str cast in enumoperators.edgeql)
  • allow casting json to tuple types
  • allow casting json to array types
Read more comments on GitHub >

github_iconTop Results From Across the Web

Optimize JSON processing with in-memory OLTP - SQL Server
To increase the performance of queries that process JSON data, you can store JSON documents in memory-optimized tables using standard string ...
Read more >
Storing JSON in Your Databases: Tips and Tricks For MySQL ...
Taking a look into performance, scale, and oddities that may occur when storing JSON in your MySQL databases.
Read more >
Laravel casting JSON to array? - php - Stack Overflow
I am casting the elements from the model so when the controllers returns JSON it does looks like a JSON object and not...
Read more >
16.20 - About JSON Type Cast - Teradata Database
Teradata provides casting functionality for a JSON type. ... This provides a performance boost in terms of data conversion.
Read more >
Working with JSON Data | Pivotal Greenplum Docs
Greenplum Database supports two JSON data types: json and jsonb . ... JSON objects are better suited than arrays for testing containment or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found