Community
    • Login

    JSON tools for viewing and editing

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    jsonviewer
    4 Posts 3 Posters 82.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Austin GilliamA
      Austin Gilliam
      last edited by PeterJones

      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

      PeterJonesP Mark OlsonM 2 Replies Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Austin Gilliam
        last edited by PeterJones

        @Austin-Gilliam ,

        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):
        162108b6-6c75-47e0-8a80-6929104a15a5-image.png

        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)

        0f7b5d92-e29f-482d-a9c5-6a0d64e97cb6-image.png

        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
        0145483e-c2b1-43c6-bb82-24f0a31c3ba6-image.png
        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.

        Austin GilliamA 1 Reply Last reply Reply Quote 3
        • Austin GilliamA
          Austin Gilliam @PeterJones
          last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • Mark OlsonM
            Mark Olson @Austin Gilliam
            last edited by Mark Olson

            @Austin-Gilliam
            It looks to me like your JSON is a JSON string representation of a JSON array. This means that the parse() 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 has result: (the result of parsing) or error: (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.

            1191f8b3-c9b2-4d98-b544-5511e06b6143-image.png

            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, to parse(@).result (which extracts the result value). Now I just click the Save 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 of Dump 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.

            1 Reply Last reply Reply Quote 4
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors