> 'display_name' from pos_order_line pol where order_id in ('164568','140750'); i will query jso" /> > 'display_name' from pos_order_line pol where order_id in ('164568','140750'); i will query jso" /> > 'display_name' from pos_order_line pol where order_id in ('164568','140750'); i will query jso"/>

How to handle invalid token "False" in postgresql

258 Views Asked by At
select replace(pol.bundle_product, '''', '"')::json ->> 'display_name' from pos_order_line pol where order_id in ('164568','140750');

i will query json data in postgresql but it shows error like this invalid input syntax for type json Details: Token "False" is invalid. Where: JSON data, line 1: ..._name": "SDBF50DV-L Package", "product_merk": False... how to handle invalid json like that?

1

There are 1 best solutions below

1
aekis.dev On

The issue it's that your bundle_product column value it's not a proper JSON value. That's why you are trying to replace single quotes with double quotes to convert it to a proper JSON value but seems that you are saving a Python dict converted as string but the boolean values aren't getting converted to JSON ones.

You need to save the result of json.dumps(dict_value) so you will be cover completely and you won't need to replace anything in your sql query. I was able to reproduce your issue.

I you wanna continue using your existing data you need to replace also True with true, False with false and also maybe None with null