litejs/json-lite

feature request - optionally decode escaped JSON string values

Closed this issue · 4 comments

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.

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.

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

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'

Done in v24.5.0