SublimePrettyJson icon indicating copy to clipboard operation
SublimePrettyJson copied to clipboard

Needs xml 2 json

Open VeryLazyBoy opened this issue 7 years ago • 6 comments

Current features are very nice to use and it would be nicer if xml 2 json is supported too.

VeryLazyBoy avatar Feb 01 '18 03:02 VeryLazyBoy

@VeryLazyBoy this is an interesting task, because there is no real mapping of xml to json, the json would likely not come out looking like you think it should. Can you provide an example xml and the json you'd want it to generate?

TerminalFi avatar May 14 '20 17:05 TerminalFi

Currently a json file can be converted to xml like the following:

{
  "glossary": {
    "title": "example glossary",
    "GlossDiv": {
      "title": "S",
      "GlossList": {
        "GlossEntry": {
          "ID": "SGML",
          "SortAs": "SGML",
          "GlossTerm": "Standard Generalized Markup Language",
          "Acronym": "SGML",
          "Abbrev": "ISO 8879:1986",
          "GlossDef": {
            "para": "A meta-markup language, used to create markup languages such as DocBook.",
            "GlossSeeAlso": [
              "GML",
              "XML"
            ]
          },
          "GlossSee": "markup"
        }
      }
    }
  }
}
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <glossary>
        <title value="example glossary"/>
        <GlossDiv>
            <title value="S"/>
            <GlossList>
                <GlossEntry>
                    <GlossDef>
                        <para value="A meta-markup language, used to create markup languages such as DocBook."/>
                        <GlossSeeAlso>
                            <items>
                                <item value="GML"/>
                                <item value="XML"/>
                            </items>
                        </GlossSeeAlso>
                    </GlossDef>
                    <GlossSee value="markup"/>
                    <Abbrev value="ISO 8879:1986"/>
                    <GlossTerm value="Standard Generalized Markup Language"/>
                    <SortAs value="SGML"/>
                    <ID value="SGML"/>
                    <Acronym value="SGML"/>
                </GlossEntry>
            </GlossList>
        </GlossDiv>
    </glossary>
</root>

It's great to just have an inversion of current json 2 xml feature.

VeryLazyBoy avatar May 15 '20 01:05 VeryLazyBoy

I see, this might be possible. I will look into it.

TerminalFi avatar May 15 '20 02:05 TerminalFi

@VeryLazyBoy I am not sure I can support a perfect 1 to 1 mapping like this easily, because XML can have many attributes, it would be hard to determine the exact format a user wants.

Turning xml2json like this, the above xml would generate the following JSON

{
    "root": {
        "glossary": {
            "title": {
                "@value": "example glossary"
            },
            "GlossDiv": {
                "title": {
                    "@value": "S"
                },
                "GlossList": {
                    "GlossEntry": {
                        "GlossDef": {
                            "para": {
                                "@value": "A meta-markup language, used to create markup languages such as DocBook."
                            },
                            "GlossSeeAlso": {
                                "items": {
                                    "item": [
                                        {
                                            "@value": "GML",
                                        },
                                        {
                                            "@value": "XML"
                                        }
                                    ]
                                }
                            }
                        },
                        "GlossSee": {
                            "@value": "markup"
                        },
                        "Abbrev": {
                            "@value": "ISO 8879:1986"
                        },
                        "GlossTerm": {
                            "@value": "Standard Generalized Markup Language"
                        },
                        "SortAs": {
                            "@value": "SGML"
                        },
                        "ID": {
                            "@value": "SGML"
                        },
                        "Acronym": {
                            "@value": "SGML"
                        }
                    }
                }
            }
        }
    }
}```

TerminalFi avatar May 15 '20 14:05 TerminalFi

Yes, I got your point. It is not an easy task. And it seems there is no convention of doing this task. As far as I am considered, this feature is no longer a high priority. You may feel free to close this issue.

VeryLazyBoy avatar May 15 '20 15:05 VeryLazyBoy

Yes, I got your point. It is not an easy task. And it seems there is no convention of doing this task. As far as I am considered, this feature is no longer a high priority. You may feel free to close this issue.

Yeah, it is just because we of xml's flexibility. If we know that it would also because "value" then it would work. Sorry about that :(

TerminalFi avatar May 15 '20 15:05 TerminalFi