SQLite Forum

Extracting original raw json string for a json_each/json_tree value
Login

Extracting original raw json string for a json_each/json_tree value

(1) By Laurence Rowe (laurencerowe) on 2021-08-19 17:49:12 [source]

I'm writing a query which restructures stored json using json_each/json_tree. To avoid true/false being output as 1/0 and to avoid precision loss for reals, I need to output the json values with something like:

CASE type
  WHEN 'true' THEN 'true'
  WHEN 'false' THEN 'false'
  WHEN 'real' THEN printf('%!.17g', value)
  ELSE json_quote(value)
END

Is there a way to extract the original raw json string for a value returned by json_each/json_tree? (The json field returns the raw string for the entire json document parsed.)