SELECT json_set('[1,2,3]', '[1]', 5::json); json_set ---------- [1,5,3] (1 row) SELECT json_set('[1,2,3]', '[3]', 5::json); json_set ---------- [1,2,3] (1 row) SELECT json_set('[1,2,3]', '[2]', 5::json); json_set ---------- [1,2,5] (1 row) SELECT json_set('[1,2,3]', '[2]', '[0,1]'::json); json_set ------------- [1,2,[0,1]] (1 row) SELECT json_set(' [ 1 , 2,3]', '1', '5'); json_set ---------------- [ 1 , 5,3] (1 row) SELECT json_set(' [ 1 , [2,3],3]', '1', '5'); json_set ---------------- [ 1 , 5,3] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ],3]', '[1][0]', '5'); json_set ------------------------------- [ 1 , [ 5 , 3 ],3] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ],3]', '[5][0]', '5'); json_set ------------------------------- [ 1 , [ 2 , 3 ],3] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ],3]', '[4][0]', '5'); json_set ------------------------------- [ 1 , [ 2 , 3 ],3] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ],3]', '[3][0]', '5'); json_set ------------------------------- [ 1 , [ 2 , 3 ],3] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ],3]', '[2][0]', '5'); json_set ------------------------------- [ 1 , [ 2 , 3 ],3] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ],3]', '[1][0]', ' 5 '); json_set ------------------------------- [ 1 , [ 5 , 3 ],3] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ] , 3 ] ', '[1][0]', ' 5 '); json_set ------------------------------------- [ 1 , [ 5 , 3 ] , 3 ] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ] , 3 ] ', '[1 ][0]', ' 5 '); json_set ------------------------------------- [ 1 , [ 5 , 3 ] , 3 ] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ] , 3 ] ', '[1 ][0]', ' 5 '); json_set ------------------------------------- [ 1 , [ 5 , 3 ] , 3 ] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ] , 3 ] ', '[1 ][0]', $$ "hello\tworld" $$); json_set -------------------------------------------------- [ 1 , [ "hello\tworld" , 3 ] , 3 ] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ] , 3 ] ', '[1 ][0]', $$ "hello\u0009world" $$); json_set ------------------------------------------------------ [ 1 , [ "hello\u0009world" , 3 ] , 3 ] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ] , 3 ] ', '[1 ][*]', $$ "hello\u0009world" $$); json_set ----------------------------------------------------------------------- [ 1 , [ "hello\u0009world" , "hello\u0009world" ] , 3 ] (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ] , 3 ] ', '$', $$ "hello\u0009world" $$); json_set ----------------------- "hello\u0009world" (1 row) SELECT json_set(' [ 1 , [ 2 , 3 ] , 3 ] ', '$', $$ "hello\u0009world" $$); json_set ---------------------------- "hello\u0009world" (1 row) -- Since JavaScript doesn't do anything when you assign to a character subscript, -- neither will json_set. SELECT json_set('"hello"', '[0]', '"H"'); json_set ---------- "hello" (1 row) SELECT json_set('"hello"', '[0][0]', '"H"'); json_set ---------- "hello" (1 row) SELECT json_set('["hello"]', '[0][0]', '"H"'); json_set ----------- ["hello"] (1 row) SELECT json_set('["hello"]', '[0][0][0]', '"H"'); json_set ----------- ["hello"] (1 row) SELECT json_set('[0,1,2,[3,4,5],4]', '$[*]', '["set"]'); json_set ------------------------------------------- [["set"],["set"],["set"],["set"],["set"]] (1 row) SELECT json_set('[0,1,2,[3,4,5],4]', '$[*][*]', '["set"]'); json_set ------------------------------------- [0,1,2,[["set"],["set"],["set"]],4] (1 row) SELECT json_set('[0,1,2,[3,4,5],4]', '$..[*]', '["set"]'); json_set ------------------------------------------- [["set"],["set"],["set"],["set"],["set"]] (1 row)