News for hackers. Stuff that matters.
Re:Show HN: Xmljson a Swift CLI Tool to Convert XML to JSON by cryptonector on Friday May 15, 2020 @04:08PM (#23196816)
And... it's wrong and busted. The children nodes of an XML node have to be represented as an array in JSON, not as an object. The only things in XML that can be represented as JSON objects (unless your converter is Schema-aware) are attributes, and PIs.

If your converter is aware of XML schemas, then child nodes that have cardinality one or zero-or-one and which have no ordering dependency relative to sibling nodes can be gathered into an object. It's just easier to use arrays for children nodes.

Put it this way: this tool, applied to a document, will butcher it.

Re:Show HN: Xmljson a Swift CLI Tool to Convert XML to JSON by p51ngh on Friday May 15, 2020 @12:33PM (#23194096)
For your sample code Python xmltodict gives:

  {
    "bookstore": {
      "book": [
        {
          "@category": "cooking",
          "title": {
            "@lang": "en",
            "#text": "Everyday 1"
          },
          "author": "Giada De Laurentiis",
          "year": "2005",
          "price": "30.00"
        },
        {
          "@category": "web",
          "title": {
            "@lang": "en",
            "#text": "Learning XML"
          },
          "author": "Erik T. Ray",
          "year": "2003",
          "price": "39.95"
        }
      ]
    }
  }
Your code gives:

  [
    {
      "author" : "Giada De Laurentiis",
      "title" : {
        "lang" : "en",
        "text" : "Everyday 1"
      },
      "year" : "2005",
      "category" : "cooking",
      "price" : "30.00"
    },
    {
      "author" : "Erik T. Ray",
      "title" : {
        "lang" : "en",
        "text" : "Learning XML"
      },
      "year" : "2003",
      "category" : "web",
      "price" : "39.95"
    }
  ]
Which one's more accurate?!!
Re:Show HN: Xmljson a Swift CLI Tool to Convert XML to JSON by alihilal94 on Friday May 15, 2020 @12:43PM (#23194217)
Thanks for your question.

Both are correct, but if you think about it we have a Bookstore with multiple books so putting them in an array of objects makes more sense.. we don't need the root element name. xmltodict just puts extra unnecessary complexity

Re:Show HN: Xmljson a Swift CLI Tool to Convert XML to JSON by benatkin on Friday May 15, 2020 @11:16AM (#23193110)
It loses the tag names in the example. Sometimes the tag names are needed. JsonML preserves them. http://www.jsonml.org/
Re:Show HN: Xmljson a Swift CLI Tool to Convert XML to JSON by alihilal94 on Friday May 15, 2020 @11:23AM (#23193215)
thanks for notifying me, feel free to open PR if you would like
Re:Show HN: Xmljson a Swift CLI Tool to Convert XML to JSON by teh_klev on Friday May 15, 2020 @10:50AM (#23192839)
Not trying to trip you up, but how do you handle namespaces?
Re:Show HN: Xmljson a Swift CLI Tool to Convert XML to JSON by alihilal94 on Friday May 15, 2020 @11:26AM (#23193249)
You're awesome good bug hunted
Re:Show HN: Xmljson a Swift CLI Tool to Convert XML to JSON by alihilal94 on Friday May 15, 2020 @09:36AM (#23191978)
Swift CLI tool for converting any XML to JSON format