How to output string values in single quotes?
Rather than retrieving the value as text with #&gt;&gt;, use #&gt; to retrieve it as json and cast it to text afterwards:

SELECT ('{"a":[1,2,3],"b":["4","5","6"]}'::json#&gt;'{b,2}')::text;

 text 
------
 "6"
(1 row)


There is also the json_typeof function that can tell you what JSON type the value has:

SELECT json_typeof('{"a":[1,2,3],"b":["4","5","6"]}'::json#&gt;'{b,2}');

 json_typeof 
-------------
 string
(1 row)