Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't Amazon Redshift Parse this Valid JSON string?

I'm using Amazon Redshift's JSON parsing abilities. Most of the time it works, but it fails in this case. I'm getting the following error:

error:  JSON parsing error
  code:      8001
  context:   invalid json object {"collection_id": 12, "activity_name": "Hour of Zen: The \"Dead Sea\" Float"}

I was under the impression that the backslash was the proper escape for the double quote (and this was automatically generated by Python's JSON package).

like image 985
DaveA Avatar asked Aug 19 '14 18:08

DaveA


People also ask

Does redshift support JSON data type?

Amazon Redshift supports the parsing of JSON data into SUPER and up to 5x faster insertion of JSON/SUPER data in comparison to inserting similar data into classic scalar columns. PartiQL is an extension of SQL that is adopted across multiple AWS services.

What is JSON parse error?

The "SyntaxError: JSON. parse: unexpected character" error occurs when passing a value that is not a valid JSON string to the JSON. parse method, e.g. a native JavaScript object. To solve the error, make sure to only pass valid JSON strings to the JSON.

Can we store JSON in redshift?

You can easily load data from JSON to Redshift via Amazon S3 or directly using third party Data Integration tools. Redshift also provides you with in-built SQL commands to carry out the data loading process. You can also use other AWS services like AWS Glue to load data from JSON to Redshift.

What is Json_extract_path_text?

The JSON_EXTRACT_PATH_TEXT function returns the value for the key:value pair referenced by a series of path elements in a JSON string. The JSON path can be nested up to five levels deep. Path elements are case-sensitive.


1 Answers

Ok, per this Redshift forum post this is a know bug, but there is no ETA for a fix. The forum recommends this workaround:

Replace:

json_extract_path_text(event_properties,'someValue')

with

json_extract_path_text(regexp_replace(event_properties,'\\\\.',''),'someValue')
like image 106
DaveA Avatar answered Sep 25 '22 16:09

DaveA