How to query my JSON data if I am currently storing it as a String in the database? #137
dario-vega
started this conversation in
Show and tell
Replies: 1 comment
-
What if I have this error?
It means that your data are already stored as JSON. Or maybe you are mixing documents with String values and JSON values. It seems really strange, but it could happen too.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Use case: I have JSON data that was stored in a string format inadvertently while inserting/updating rows. The operation succeeded because the string data is a valid JSON. However, the fields are populated with the unparsed string.
It seems strange, but it happens very often, especially when receiving data from 3rd parties.
Let's take a look at the following data
Here, the
jsonString
field is populated as a complete string. ThejsonWithStrings
field has a doc attribute, which is JSON, however, the value is a string instead of a JSON. ThefullJson
field is a proper JSON document.Updating to have a more complex JSON example - adding Author and site
Okay, but how to query my data using JSON queries? Simply use the parse_json function
Without using parse_json
Of course, the best practice is always to store JSON as JSON and not as Strings or mix both inside a JSON, but sometimes it is happening. By the way, you can use this function in the DDL statements to parse and insert it as JSON.
Beta Was this translation helpful? Give feedback.
All reactions