3

I just realized that the data being inserted into a JSONB column is a string like "{\"foo\": 3}" instead of an object like {"foo": 3}. I'm pretty sure the cause is due to setting the SQLAlchemy model's field with

reading.blob = blob_json

instead of

reading.blob = json.loads(blob_json)

I haven't been able to figure out a way to correct the existing data, though. The Postgres docs give examples of converting text to JSON, extracting array and object elements out of JSON, etc., but I can't find anything that shows how to select the text of a JSONB column that has only one string value.

2 Answers 2

5

Yes, just when I got this:

SELECT (('"{\"foo\":42}"'::JSONB)->>0)::JSONB;
Sign up to request clarification or add additional context in comments.

Comments

4

Eureka! DeciBull on #postgres came up with

SELECT (json_build_array('"{\"Stuff.Hello\": 0, \"Stuff.Hello2\": 1000}"'::jsonb)->>0)::jsonb

{"Stuff.Hello": 0, "Stuff.Hello2": 1000}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.