Menurut Dokumentasi Postgres :
IMHO Anda memberikan string berformat JSON, maka Anda harus menggunakan metode pertama.
to_json('Fred said "Hi."'::text) --> "Fred said \"Hi.\""
Jika Anda mencoba mendapatkan array elemen menggunakan to_json(text) Anda akan mendapatkan kesalahan berikutnya:
select *
from jsonb_array_elements_text(to_jsonb('[{"field":15,"operator":0,"value":"1"},{"field":15,"operator":0,"value":"2"},55]'::text));
Tetapi jika Anda sebelumnya melemparkannya ke json:
select *
from jsonb_array_elements_text(to_jsonb('[{"field":15,"operator":0,"value":"1"},{"field":15,"operator":0,"value":"2"},55]'::json));
+--------------------------------------------+
| value |
+--------------------------------------------+
| {"field": 15, "value": "1", "operator": 0} |
+--------------------------------------------+
| {"field": 15, "value": "2", "operator": 0} |
+--------------------------------------------+
| 55 |
+--------------------------------------------+