I have strings representing jsons where field names and values are enclosed in single quotes, for example {'name': 'Grzegorz', 'age': 123}. Let's assume that I have also a table in postgres database:
CREATE TABLE item (
metadata jsonb
);
I'm trying to insert rows using JOOQ. JOOQ generates the following statement:
insert into Item values('{''name'': ''Grzegorz'', ''age'': 123}'::jsonb); but an error is thrown:
ERROR: invalid input syntax for type json
LINE 1: insert into Item values('{''name'': ''Grzegorz'', ''age'': 1...
Token "'" is invalid.
JSON data, line 1: {'...
Is there any possibility to insert json with names enclosed in single quotes ' instead of double quotes " or should I convert all ' to "?
Thanks in advance!
Grzegorz
{'name': 'Grzegorz', 'age': 123}can be a valid javascript value, but not a valid JSON. Blindly converting all'to"could be dangerous, just consider f.ex.{'name': 'Gregor "Grzegorz"', 'age': 123}(if that's a possible generated value, because that's too could be parsed with javascript). Instead, I would look into how these values are generated & search for a method to generate valid JSON values.