JSON tools for viewing and editing
-
I just installed the JsonTools plugin to easily view and edit my json file, but it doesn’t seem to recognize the format I’m using. Here’s an example:
"{\"FastenerData\":{\"508670\":{\"Item1\":\"10\",\"Item2\":\"50\"},\"508674\":{\"Item1\":\"10\",\"Item2\":\"50\"}}}"
I don’t know if I can change some settings or if I need a different plugin, but none of my searches have turned up any useful info. Could someone point me in the right direction?
Also, that format is the output from the System.Text.Json serializer. I just can’t figure out how to view properly in Notepad++.
—
moderator added code markdown around text; please don’t forget to use the
</>
button to mark example text as “code” so that characters don’t get changed by the forum -
What you have there is a string that’s got JSON embedded in it – I think you may have double-encoded it: maybe you serialized the serialization of your data? (I’m not a JSON expert, nor do I know what tool
System.Text.Json
serializer is in, nor how to use it. So I cannot tell you why your data is in that state)However, even not being a user of JSON Tools, but just knowing a tiny bit about reading normal JSON files and being able to install the JSON Tools plugin, I was able to get it to try to look at the tree and see that it thought it was a string (at least, that’s what I interpreted the abc prefix to mean):
By reading through the menu entries, I was able to guess that the helpful command would be one of two commands at the bottom, which looked like they convert text encoded string back into raw JSON.
In my experiments, I wrongly tried Dump selected text as JSON string(s) first, but that encoded it even more (more backslashes and quotes)
So then I went back to the original, and used Dump JSON string(s) as raw text, which spawned the results into a new file, and the file looked like
{"FastenerData":{"508670":{"Item1":"10","Item2":"50"},"508674":{"Item1":"10","Item2":"50"}}}
When I clicked Refresh in the tree viewer, and expanded the tree, I saw
which is what you want.So if you get something that starts
"{\"...
, you can paste that into Notepad++, use the Plugins > JSON Tools > Dump JSON string(s) as raw text, which will open it in a new tab, and that new tab should be reasonable JSON for you to work with and see in the JSON Tools TreeView panel.Good luck.
-
@PeterJones Thank you so much! The serializer is what I use in my C# program to convert a class to json. Now that I know what the issue is, hopefully I can figure out a way to change my output.
-
@Austin-Gilliam
It looks to me like your JSON is a JSON string representation of a JSON array. This means that theparse()
RemesPath function (follow that link, then find the parse() function) will help you. It attempts to parse a JSON string, and returns an object that either hasresult: (the result of parsing)
orerror: (the error that caused parsing to fail)
. Note that this function was added in a pretty recent version (v5.5.0), so you might want to get the latest version if that query fails.Here’s an image of what we get with your JSON.
As you can see from the treeview on the right, the
parse()
function worked. Since we know it’s successful, I’ll just change the query slightly, toparse(@).result
(which extracts theresult
value). Now I just click theSave query result
button above the tree, and the parsed array is saved in a new buffer. The contents of this buffer will be as follows:{ "FastenerData": { "508670": {"Item1": "10", "Item2": "50"}, "508674": {"Item1": "10", "Item2": "50"} } }
By the way, I’m the maintainer of JsonTools, and you can always raise an issue in the repo (linked here) if you need help. But this is a fine place to do it as well.
@PeterJones
I’m pleased to see that you noticed the potential ofDump JSON string(s) as raw text
in this situation. I was just about to mention it, but I saw you beat me to the punch.