format · validate · convert · runs locally

Parse JSON in SQL

How to parse a JSON string into an object and serialize (stringify) an object back to JSON in SQL. PostgreSQL has native json/jsonb types; MySQL uses JSON_EXTRACT and JSON_OBJECT. Need to clean up the JSON first? Use the formatter & validator.

Parse JSON (string → object)

-- PostgreSQL: cast text to jsonb
SELECT '{"id":1}'::jsonb AS obj;
SELECT obj->>'id' AS id FROM t;

Stringify (object → JSON string)

-- Build JSON from columns
SELECT jsonb_pretty(
  jsonb_build_object('id', id, 'name', name)
) FROM t;

Frequently asked questions

How do I parse JSON in SQL?

PostgreSQL has native json/jsonb types; MySQL uses JSON_EXTRACT and JSON_OBJECT. Parse with the snippet above; the result is a native object/map you can read.

How do I pretty-print JSON in SQL?

Use the stringify snippet above with indentation, or paste your JSON into the formatter on this page.