[Feature request] Detect if a string value contains JSON and provide an option to format it
Closed this issue · 9 comments
Quite often I have embedded JSON in string values, like this:
{
"request": "{\"url\":\"http://...\",\"headers\":[{\"name\":\"Accept\",\"value\":\"application/json\"}]}"
}
It would be great if MJsonViewer detected that "request" value string contains JSON inside and provided some option to replace the string with nicely formatted JSON object:
{
"request": {
"url": "http://...",
"headers": [
{
"name": "Accept",
"value": "application/json"
}
]
}
}
This should probably be done "on demand", rather than controlled with a global option.
The new version has been uploaded, waiting for the validating.
In the new version, you can click on the embedded json string, it will show the structure. Like the image in the readme file. Although it is ugly so far, I will find a better way to solve it.
Thank you. It is already a great help compared to "counting the brackets".
There are a few quirks though.
- '<' and '>' in the strings inside embedded JSON are replaced with '<' and '>'
For example, this value"{\"data\":\"<div>Hello</div>\"}"
when clicked is displayed like this:
{
"data": "<div>Hello</div>"
}
- Probably because of that formatted embedded JSON is trimmed at the end and is not shown completely
Frankly speaking I imagined this "embedded JSON" will be injected into the parent document replacing the string value.
This way I would be able to use all the MJsonViewer features to work with it (folding, navigating links, etc.)
It's probably not a good idea to do such replacement on a simple click. So I imagined there would be some specific action that a user could trigger on demand.
For example, if add-on detected that a string contains JSON it could show a "parse" button before the value, like this:
{
"data": [parse] "{\"embedded\":\"JSON\"}"
}
And then clicking that button would change the main document to
{
"data": {
"embedded": "JSON"
}
}
What do you think?
Yes, that is exactly what I want to do next. But it will change the original code structure. It may take a little long time.
JSON detection does not work right for some cases. For example, the following value is recognized as JSON:
"http://example.com/some/url/with/{placeholder}"
.
Also the URL clickable area covers the inline buttons too:
Clicking on the button shows the JSON popup and then immediately loads the linked page.
Try v3.4?
The links are not clickable anymore in version 3.5
Yes, it will not support.
What did you mean with "it will not support"?
Are you not going to make links clickable?
This is very important feature for me. So for now I have to use some other JSON viewer add-on.