litejs / json-lite

Fast non-blocking JSON viewer for Chrome and Firefox
195 stars 16 forks source link

feature request - optionally decode escaped JSON string values #70

Closed elaw-fastly closed 3 months ago

elaw-fastly commented 11 months ago

Many times I view JSON files that have embedded/escaped JSON strings for many field values. A hypothetical example might look like this { "result" : "{\"code\":4,\"message\":\"ouch that hurt\"}", "list": "[\"one\",\"two\",\"three\"]" }

Sometimes the JSON has multiple levels of this escaping going on. It would be nice to be able to click, doubleclick, or {metakey}-click, etc to decode embedded/escaped JSON within a JSON payload.

elaw-fastly commented 11 months ago

This is not the same as the 'Auto-unescape strings' option already provided. The strings being unescaped are actual JSON structures. I'd like to see them replaced in-line as actual JSON.

lauriro commented 11 months ago

It can be done with two steps but sure one step would be better.

  1. select string with beginning/ending quote and click "Decode->JSON.parse" from right-click-menu "[\"one\",\"two\",\"three\"]"
  2. select "format selection" from right-click-menu
elaw-fastly commented 10 months ago

I tried highlighting the text within quotes of the 'result' value and I get an error: SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2)

While most of the JSON I attempted to format looks basically correct, there seems to be a lot of actual '\' in the data, as if the selected text was not un-escaped of \"

This occurs whether the plugin is configured to auto-unescape strings or not.

My actual payload is 166KiB. When decoding with jq everything looks ok: cat example.json | jq '.result|fromjson'

lauriro commented 3 months ago

Done in v24.5.0