1

I have some JSON I'm trying to insert into a Postgres database but I can't manage to properly escape the quotes, here's my code

insert into Product_Templates (product) values( '{
"template_id": "OSBSheet",
"name":'Exterior Wall Using 2\"x4\"x96\" Studs, Double Top Plate'

}

I get the error: invalid command \"x96

How do I work around this?

1 Answer 1

1

See the JSON syntax. The keys and string values in JSON are enclosed in double quotes. The quotation marks in strings must be preceded by a "\" character:

select
'{
    "template_id": "OSBSheet",
    "name": "Exterior Wall Using 2\"x4\"x96\" Studs, Double Top Plate"
}'::jsonb

                                              jsonb                                              
-------------------------------------------------------------------------------------------------
 {"name": "Exterior Wall Using 2\"x4\"x96\" Studs, Double Top Plate", "template_id": "OSBSheet"}
(1 row) 
Sign up to request clarification or add additional context in comments.

2 Comments

I've changed that, I still get the same error, invalid command \"x96
Thanks, the issue was with other inserts above that were improperly formatted

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.