๐ŸŒ
JSON Formatter
jsonformatter.org โ€บ xml-to-json
Best XML to JSON Converter Online
XML to JSON is very unique tool for convert JOSN to XML and allows to download, save, share and print XML to JSON data..
๐ŸŒ
FreeFormatter
freeformatter.com โ€บ xml-to-json-converter.html
Free Online XML to JSON Converter - FreeFormatter.com
This free online tool lets you convert an XML file into a JSON file with your choice of indentation
๐ŸŒ
Convertjson
convertjson.com โ€บ xml-to-json.htm
Convert XML to JSON
The tool will convert a XML file to JSON format.
๐ŸŒ
GitHub
github.com โ€บ sinelaw โ€บ xml-to-json-fast
GitHub - sinelaw/xml-to-json-fast: Fast, light converter of xml to json capable of handling huge xml files
Fast, light converter of xml to json capable of handling huge xml files ยท The fast, simple xml-to-json-fast executable provides an unambiguous one-to-one mapping of xml data to json data.
Starred by 48 users
Forked by 6 users
Languages ย  Haskell 100.0% | Haskell 100.0%
๐ŸŒ
Altova
altova.com โ€บ xmlspy-xml-editor โ€บ xml-to-json
XML to JSON Converter | Altova
In addition to powerful conversion utilities, XMLSpy includes a JSON and XML editors, as well as support for working with XPath, XSLT, and XQuery alongside both technologies. You can convert a single file or perform a mass conversion on a large number of XML files instantly.
๐ŸŒ
Online XML Tools
onlinexmltools.com โ€บ convert-xml-to-json
Convert XML to JSON - Online XML Tools
Free online XML to JSON converter. Just paste your XML in the form below and it will automatically get converted to JSON. There are no ads, popups or nonsense, just an awesome XML to JSON converter. Paste XML, get JSON.
๐ŸŒ
SourceForge
sourceforge.net โ€บ projects โ€บ xml2json-converter
Xml2Json Converter download | SourceForge.net
Xml2Json Converter
Download Xml2Json Converter for free. Simple tool for converting large XML-files to JSON or JSON to XML. Simple converter tool with GUI (written on JavaFX) for converting large XML-files to JSON and JSON to XML with indicating progress and uses small amount of memory for converting. Simple converter tool with GUI (written on JavaFX) for converting large XML-files to JSON and JSON to XML with indicating progress and uses small amount of memory for converting. ยท Starting from 1.2.0 application supports batch converting files from directory by pattern. ยท Uses Java 1.8+ (http://www.oracle.com/tech
Rating: 4 โ€‹
๐ŸŒ
GitHub
github.com โ€บ sinelaw โ€บ xml-to-json
GitHub - sinelaw/xml-to-json: Fast & easy command line tool for converting XML files to JSON ยท GitHub
Fast & easy library & command line tool for converting XML files to JSON.
Starred by 102 users
Forked by 21 users
Languages ย  Haskell 88.8% | Shell 6.7% | JavaScript 4.5%
๐ŸŒ
Code Beautify
codebeautify.org โ€บ xmltojson
XML to JSON Converter Online to convert XML to JSON String, URL and File
If you're looking for an easy way to convert XML to JSON, you've come to the right place. Our XML to JSON converter is free and easy to use, simply paste your XML code into the input and hit the "XML to JSON" button.
๐ŸŒ
Conversion Tools
conversiontools.io โ€บ convert โ€บ xml-to-json
Convert XML to JSON Online | XML to JSON Converter
XML to JSON Converter. Convert XML to JSON Online with Free Converter. Import XML, Save JSON. XML conversion to JSON. API available.
Find elsewhere
Top answer
1 of 3
10

Many Python XML libraries support parsing XML sub elements incrementally, e.g. xml.etree.ElementTree.iterparse and xml.sax.parse in the standard library. These functions are usually called "XML Stream Parser".

The xmltodict library you used also has a streaming mode. I think it may solve your problem

https://github.com/martinblech/xmltodict#streaming-mode

2 of 3
4

Instead of trying to read the file in one go and then process it, you want to read it in chunks and process each chunk as it's loaded. This is a fairly common situation when processing large XML files and is covered by the Simple API for XML (SAX) standard, which specifies a callback API for parsing XML streams - it's part of the Python standard library under xml.sax.parse and xml.etree.ETree as mentioned above.

Here's a quick XML to JSON converter:

from collections import defaultdict
import json
import xml.etree.ElementTree as ET

def parse_xml(file_name):
    events = ("start", "end")
    context = ET.iterparse(file_name, events=events)

    return pt(context)

def pt(context, cur_elem=None):
    items = defaultdict(list)

    if cur_elem:
        items.update(cur_elem.attrib)

    text = ""

    for action, elem in context:
        # print("{0:>6} : {1:20} {2:20} '{3}'".format(action, elem.tag, elem.attrib, str(elem.text).strip()))

        if action == "start":
            items[elem.tag].append(pt(context, elem))
        elif action == "end":
            text = elem.text.strip() if elem.text else ""
            elem.clear()
            break

    if len(items) == 0:
        return text

    return { k: v[0] if len(v) == 1 else v for k, v in items.items() }

if __name__ == "__main__":
    json_data = parse_xml("large.xml")
    print(json.dumps(json_data, indent=2))

If you're looking at a lot of XML processing check out the lxml library, it's got a ton of useful stuff over and above the standard modules, while also being much easier to use.

http://lxml.de/tutorial.html

๐ŸŒ
CodeShack
codeshack.io โ€บ home โ€บ tools โ€บ xml to json converter
XML to JSON Converter
Convert XML into JSON format online, save the output to a file or copy and paste into your projects. Free to use online tool, quickly convert any XML file or text.
Top answer
1 of 2
2

Try the recommended Microsoft technique: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/how-to-perform-streaming-transform-of-large-xml-documents

So, for example, you have the following part of code:

                while (reader.Read())  
                {  
                    if (reader.NodeType == XmlNodeType.EndElement)  
                        break;  
                    if (reader.NodeType == XmlNodeType.Element  
                        && reader.Name == "Item")  
                    {  
                        item = XElement.ReadFrom(reader) as XElement;  
                        if (item != null)  
                        {  
                            //here you can get data from your array object
                            //and put it to your JSON stream
                        }  
                    }  
                } 

If you want to define the type of element you can check if it has children: How to check if XElement has any child nodes?

It should work good in pair with streaming of JSON. For more info about JSON steaming look into: Writing JSON to a stream without buffering the string in memory

2 of 2
1

Huge files always require using XmlReader. I use a combination of XmlReader and Xml Linq in code below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace ConsoleApplication120
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            List<Dictionary<string, string>> items = new List<Dictionary<string, string>>();
            XmlReader reader = XmlReader.Create(FILENAME);

            reader.ReadToFollowing("hugeArray");

            while (!reader.EOF)
            {
                if (reader.Name != "item")
                {
                    reader.ReadToFollowing("item");
                }
                if (!reader.EOF)
                {
                    XElement item = (XElement)XElement.ReadFrom(reader);
                    Dictionary<string, string> dict = item.Elements()
                        .GroupBy(x => x.Name.LocalName, y => (string)y)
                        .ToDictionary(x => x.Key, y => y.FirstOrDefault());

                    items.Add(dict);
                }
            }
        }
    }


}
๐ŸŒ
Hackage
hackage.haskell.org โ€บ package โ€บ xml-to-json-fast
xml-to-json-fast: Fast, light converter of xml to json capable of handling huge xml files
If not input file is given, reads from stdin (so it can be used in a unix pipe chain). ... The fast, simple xml-to-json-fast executable provides an unambiguous one-to-one mapping of xml data to json data. It is suitable for very large xml files (has been tested on a 500MB file) and uses very ...
๐ŸŒ
JSONLint
jsonlint.com โ€บ xml-to-json
XML to JSON Converter - Transform XML Data Online | JSONLint | JSONLint
Convert XML to JSON instantly. Handles attributes, namespaces, and nested elements. Preview the result and copy or download the converted JSON.
๐ŸŒ
Oxygen XML
oxygenxml.com โ€บ doc โ€บ ug-editor โ€บ topics โ€บ convert-XML-to-JSON-x-tools.html
XML to JSON Converter
Select the Open in Editor option to open the resulting JSON document in the main editing pane. Click the Convert button. Result: The original XML document is now converted to a JSON document.
๐ŸŒ
BeautifyTools
beautifytools.com โ€บ xml-to-json-converter.php
XML To JSON Converter - BeautifyTools.com
XML To JSON Converter converts XML to JSON online. Select, Load or Enter XML and convert XML to JSON. Beautify or Minify XML, JSON and download JSON data in a file.
๐ŸŒ
Teleport
goteleport.com โ€บ resources โ€บ tools โ€บ xml-to-json-converter
XML to JSON Converter | Instant XML to JSON Conversion | Teleport
Convert XML data to JSON instantly with our free online tool. Simplify your data conversions with fast, accurate processing.
๐ŸŒ
Microsoft Store
apps.microsoft.com โ€บ detail โ€บ 9p6pfjvgdmlx
Xml to Json Converter pro - Download and install on Windows | Microsoft Store
Supports Large Files: Capable of processing and converting large XML files. High Security: Your data is protected during the conversion process, with no data stored or transferred without your permission. Standards Compliant: Keeps up with the latest XML and JSON technical standards to ensure ...
๐ŸŒ
Site24x7
site24x7.com โ€บ tools โ€บ xml-to-json.html
XML to JSON Converter: Site24x7 Tools
Free tool which converts your XML data to its equivalent JSON format.The XML elements are converted to JSON keys and element values are transformed to corresponding JSON values.