json2xml 6.0.6__tar.gz → 6.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {json2xml-6.0.6 → json2xml-6.1.0}/CONTRIBUTING.rst +12 -1
- {json2xml-6.0.6 → json2xml-6.1.0}/HISTORY.rst +14 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/PKG-INFO +177 -47
- {json2xml-6.0.6 → json2xml-6.1.0}/README.rst +176 -46
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/usage.rst +46 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml/__init__.py +1 -1
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml/cli.py +36 -15
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml/dicttoxml.py +25 -24
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml/json2xml.py +3 -2
- json2xml-6.1.0/json2xml/types.py +8 -0
- json2xml-6.1.0/json2xml/utils.py +73 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml.egg-info/PKG-INFO +177 -47
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml.egg-info/SOURCES.txt +2 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/pyproject.toml +1 -2
- {json2xml-6.0.6 → json2xml-6.1.0}/setup.cfg +1 -1
- {json2xml-6.0.6 → json2xml-6.1.0}/tests/test_cli.py +35 -5
- {json2xml-6.0.6 → json2xml-6.1.0}/tests/test_dict2xml.py +71 -1
- json2xml-6.1.0/tests/test_dicttoxml_fast_fallback.py +98 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/tests/test_json2xml.py +17 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/tests/test_rust_dicttoxml.py +21 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/tests/test_utils.py +66 -79
- json2xml-6.0.6/json2xml/utils.py +0 -55
- {json2xml-6.0.6 → json2xml-6.1.0}/AUTHORS.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/LICENSE +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/MANIFEST.in +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/Makefile +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/authors.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/benchmarks.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/conf.py +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/contributing.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/history.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/index.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/installation.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/json2xml.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/make.bat +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/modules.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/docs/readme.rst +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml/dicttoxml_fast.py +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml.egg-info/dependency_links.txt +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml.egg-info/entry_points.txt +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml.egg-info/requires.txt +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/json2xml.egg-info/top_level.txt +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/requirements.in +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/setup.py +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/tests/__init__.py +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/tests/conftest.py +0 -0
- {json2xml-6.0.6 → json2xml-6.1.0}/tests/test_missing_coverage.py +0 -0
|
@@ -9,6 +9,17 @@ helps, and credit will always be given.
|
|
|
9
9
|
|
|
10
10
|
You can contribute in many ways:
|
|
11
11
|
|
|
12
|
+
Good First Contributions
|
|
13
|
+
------------------------
|
|
14
|
+
|
|
15
|
+
If you are new to the project, these are useful places to start:
|
|
16
|
+
|
|
17
|
+
* Improve examples for real-world API responses, files, and command-line usage.
|
|
18
|
+
* Add small tests around conversion options such as wrappers, list handling, CDATA, and XPath output.
|
|
19
|
+
* Improve benchmark documentation or add a reproducible benchmark case.
|
|
20
|
+
* Polish CLI behavior, error messages, and help text.
|
|
21
|
+
* Review the roadmap in ``ROADMAP.md`` and open a focused issue before starting larger changes.
|
|
22
|
+
|
|
12
23
|
Types of Contributions
|
|
13
24
|
----------------------
|
|
14
25
|
|
|
@@ -99,7 +110,7 @@ Ready to contribute? Here's how to set up `json2xml` for local development.
|
|
|
99
110
|
Rust Extension Development
|
|
100
111
|
--------------------------
|
|
101
112
|
|
|
102
|
-
The ``json2xml-rs`` Rust extension provides ~
|
|
113
|
+
The ``json2xml-rs`` Rust extension provides ~57-129x faster performance in the current benchmark. If you want to contribute to the Rust extension:
|
|
103
114
|
|
|
104
115
|
**Prerequisites**
|
|
105
116
|
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
|
|
2
|
+
6.1.0 / 2026-05-04
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* fix: address open contribution issues (#292)
|
|
6
|
+
* docs: improve README and add public roadmap (#287)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
6.0.7 / 2026-04-26
|
|
10
|
+
==================
|
|
11
|
+
|
|
12
|
+
* fix: handle JSON conversion edge cases and improve URL reader robustness (#284)
|
|
13
|
+
* chore(deps-dev): bump pytest from 9.0.1 to 9.0.3 (#282)
|
|
14
|
+
|
|
15
|
+
|
|
2
16
|
6.0.6 / 2026-04-08
|
|
3
17
|
==================
|
|
4
18
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: json2xml
|
|
3
|
-
Version: 6.0
|
|
3
|
+
Version: 6.1.0
|
|
4
4
|
Summary: Simple Python Library to convert JSON to XML
|
|
5
5
|
Author-email: Vinit Kumar <mail@vinitkumar.me>
|
|
6
6
|
License: Apache Software License 2.0
|
|
@@ -54,7 +54,7 @@ json2xml
|
|
|
54
54
|
.. image:: https://codecov.io/gh/vinitkumar/json2xml/branch/master/graph/badge.svg?token=Yt2h55eTL2
|
|
55
55
|
:target: https://codecov.io/gh/vinitkumar/json2xml
|
|
56
56
|
|
|
57
|
-
json2xml is a Python library
|
|
57
|
+
json2xml is a Python library and CLI for converting JSON data into XML. It is designed for teams that need predictable XML output, Python-first ergonomics, and a faster native path when conversion speed matters.
|
|
58
58
|
|
|
59
59
|
Documentation: https://json2xml.readthedocs.io.
|
|
60
60
|
|
|
@@ -62,6 +62,137 @@ The library was initially dependent on the `dict2xml` project, but it has now be
|
|
|
62
62
|
|
|
63
63
|
**Looking for a Go version?** Check out `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_, a Go port of this library with identical features and a native CLI tool.
|
|
64
64
|
|
|
65
|
+
Why json2xml?
|
|
66
|
+
^^^^^^^^^^^^^
|
|
67
|
+
|
|
68
|
+
Use json2xml when you need:
|
|
69
|
+
|
|
70
|
+
* A Python library for turning dictionaries, strings, files, or API responses into XML
|
|
71
|
+
* A command-line tool for quick JSON-to-XML conversion from scripts and terminals
|
|
72
|
+
* Optional Rust acceleration with automatic fallback to the pure Python implementation
|
|
73
|
+
* XPath 3.1 compatible output when standards-friendly XML is required
|
|
74
|
+
* A small, focused project with tests, docs, benchmarks, and multiple native implementation experiments
|
|
75
|
+
|
|
76
|
+
Quick Start
|
|
77
|
+
^^^^^^^^^^^
|
|
78
|
+
|
|
79
|
+
Install the Python package:
|
|
80
|
+
|
|
81
|
+
.. code-block:: console
|
|
82
|
+
|
|
83
|
+
pip install json2xml
|
|
84
|
+
|
|
85
|
+
Use it from Python:
|
|
86
|
+
|
|
87
|
+
.. code-block:: python
|
|
88
|
+
|
|
89
|
+
from json2xml import json2xml
|
|
90
|
+
from json2xml.utils import readfromstring
|
|
91
|
+
|
|
92
|
+
data = readfromstring('{"name": "Ada", "language": "Python"}')
|
|
93
|
+
print(json2xml.Json2xml(data).to_xml())
|
|
94
|
+
|
|
95
|
+
Use it from the terminal:
|
|
96
|
+
|
|
97
|
+
.. code-block:: console
|
|
98
|
+
|
|
99
|
+
json2xml-py -s '{"name": "Ada", "language": "Python"}'
|
|
100
|
+
|
|
101
|
+
Install the accelerated path:
|
|
102
|
+
|
|
103
|
+
.. code-block:: console
|
|
104
|
+
|
|
105
|
+
pip install json2xml[fast]
|
|
106
|
+
|
|
107
|
+
Real-world Examples
|
|
108
|
+
^^^^^^^^^^^^^^^^^^^
|
|
109
|
+
|
|
110
|
+
Convert a JSON API response in Python when another system expects XML:
|
|
111
|
+
|
|
112
|
+
.. code-block:: python
|
|
113
|
+
|
|
114
|
+
from json2xml import json2xml
|
|
115
|
+
|
|
116
|
+
api_response = {"user": {"id": 7, "name": "Ada"}, "active": True}
|
|
117
|
+
print(json2xml.Json2xml(api_response, pretty=False).to_xml().decode("utf-8"))
|
|
118
|
+
|
|
119
|
+
Output:
|
|
120
|
+
|
|
121
|
+
.. code-block:: xml
|
|
122
|
+
|
|
123
|
+
<?xml version="1.0" encoding="UTF-8" ?><all><user type="dict"><id type="int">7</id><name type="str">Ada</name></user><active type="bool">true</active></all>
|
|
124
|
+
|
|
125
|
+
Convert a local JSON export from the shell:
|
|
126
|
+
|
|
127
|
+
.. code-block:: console
|
|
128
|
+
|
|
129
|
+
cat > orders.json <<'JSON'
|
|
130
|
+
{"orders":[{"id":"A100","total":19.99},{"id":"A101","total":5.5}]}
|
|
131
|
+
JSON
|
|
132
|
+
json2xml-py --no-pretty --no-type orders.json
|
|
133
|
+
|
|
134
|
+
Output:
|
|
135
|
+
|
|
136
|
+
.. code-block:: xml
|
|
137
|
+
|
|
138
|
+
<?xml version="1.0" encoding="UTF-8" ?><all><orders><item><id>A100</id><total>19.99</total></item><item><id>A101</id><total>5.5</total></item></orders></all>
|
|
139
|
+
|
|
140
|
+
Convert stdin in a shell pipeline:
|
|
141
|
+
|
|
142
|
+
.. code-block:: console
|
|
143
|
+
|
|
144
|
+
printf '%s\n' '{"event":"deploy","status":"ok"}' | json2xml-py --no-pretty --no-type -
|
|
145
|
+
|
|
146
|
+
Output:
|
|
147
|
+
|
|
148
|
+
.. code-block:: xml
|
|
149
|
+
|
|
150
|
+
<?xml version="1.0" encoding="UTF-8" ?><all><event>deploy</event><status>ok</status></all>
|
|
151
|
+
|
|
152
|
+
Performance Snapshot
|
|
153
|
+
^^^^^^^^^^^^^^^^^^^^
|
|
154
|
+
|
|
155
|
+
The optional Rust extension is the fastest path for Python callers because it avoids process startup overhead and falls back to pure Python when a feature is not supported natively.
|
|
156
|
+
|
|
157
|
+
.. list-table::
|
|
158
|
+
:header-rows: 1
|
|
159
|
+
:widths: 30 20 20 15
|
|
160
|
+
|
|
161
|
+
* - Test Case
|
|
162
|
+
- Pure Python
|
|
163
|
+
- Rust Extension
|
|
164
|
+
- Speedup
|
|
165
|
+
* - **Small JSON** (47 bytes)
|
|
166
|
+
- 31.49µs
|
|
167
|
+
- 0.55µs
|
|
168
|
+
- **56.8x**
|
|
169
|
+
* - **Medium JSON** (3.2 KB)
|
|
170
|
+
- 1.69ms
|
|
171
|
+
- 16.15µs
|
|
172
|
+
- **105.0x**
|
|
173
|
+
* - **Large JSON** (32 KB)
|
|
174
|
+
- 17.97ms
|
|
175
|
+
- 168.21µs
|
|
176
|
+
- **106.8x**
|
|
177
|
+
* - **Very Large JSON** (323 KB)
|
|
178
|
+
- 183.33ms
|
|
179
|
+
- 1.42ms
|
|
180
|
+
- **129.0x**
|
|
181
|
+
|
|
182
|
+
See `BENCHMARKS.md <https://github.com/vinitkumar/json2xml/blob/master/BENCHMARKS.md>`_ for the full Python, Rust, Go, and Zig comparison.
|
|
183
|
+
|
|
184
|
+
Project Roadmap
|
|
185
|
+
^^^^^^^^^^^^^^^
|
|
186
|
+
|
|
187
|
+
The next phase of json2xml is focused on making the project easier to adopt, benchmark, and contribute to:
|
|
188
|
+
|
|
189
|
+
* Improve examples for common API, file, and CLI workflows
|
|
190
|
+
* Add clearer contribution paths for docs, CLI polish, and benchmark coverage
|
|
191
|
+
* Keep comparing Python, Rust, Go, and Zig implementations with reproducible benchmarks
|
|
192
|
+
* Continue hardening the Rust extension fallback behavior across platforms
|
|
193
|
+
|
|
194
|
+
See `ROADMAP.md <https://github.com/vinitkumar/json2xml/blob/master/ROADMAP.md>`_ for more detail.
|
|
195
|
+
|
|
65
196
|
|
|
66
197
|
|
|
67
198
|
Architecture Diagram
|
|
@@ -79,7 +210,7 @@ Installation
|
|
|
79
210
|
|
|
80
211
|
pip install json2xml
|
|
81
212
|
|
|
82
|
-
**With Native Rust Acceleration (up to
|
|
213
|
+
**With Native Rust Acceleration (up to 129x faster)**
|
|
83
214
|
|
|
84
215
|
For maximum performance, install the optional Rust extension:
|
|
85
216
|
|
|
@@ -91,7 +222,7 @@ For maximum performance, install the optional Rust extension:
|
|
|
91
222
|
# Or install the Rust extension separately
|
|
92
223
|
pip install json2xml-rs
|
|
93
224
|
|
|
94
|
-
The Rust extension provides **
|
|
225
|
+
The Rust extension provides **57-129x faster** conversion compared to pure Python in the latest benchmark. It's automatically used when available, with seamless fallback to pure Python.
|
|
95
226
|
|
|
96
227
|
**As a CLI Tool**
|
|
97
228
|
|
|
@@ -337,7 +468,7 @@ Using tools directly:
|
|
|
337
468
|
|
|
338
469
|
**Rust Extension Development**
|
|
339
470
|
|
|
340
|
-
The optional Rust extension (``json2xml-rs``) provides up to
|
|
471
|
+
The optional Rust extension (``json2xml-rs``) provides up to 129x faster performance in the latest benchmark. To develop or build the Rust extension:
|
|
341
472
|
|
|
342
473
|
Prerequisites:
|
|
343
474
|
|
|
@@ -464,21 +595,21 @@ For users who need maximum performance within Python, json2xml includes an optio
|
|
|
464
595
|
- Rust Extension
|
|
465
596
|
- Speedup
|
|
466
597
|
* - **Small JSON** (47 bytes)
|
|
467
|
-
-
|
|
468
|
-
-
|
|
469
|
-
- **
|
|
598
|
+
- 31.49µs
|
|
599
|
+
- 0.55µs
|
|
600
|
+
- **56.8x**
|
|
470
601
|
* - **Medium JSON** (3.2 KB)
|
|
471
|
-
-
|
|
472
|
-
- 15µs
|
|
473
|
-
- **
|
|
602
|
+
- 1.69ms
|
|
603
|
+
- 16.15µs
|
|
604
|
+
- **105.0x**
|
|
474
605
|
* - **Large JSON** (32 KB)
|
|
475
|
-
-
|
|
476
|
-
-
|
|
477
|
-
- **
|
|
606
|
+
- 17.97ms
|
|
607
|
+
- 168.21µs
|
|
608
|
+
- **106.8x**
|
|
478
609
|
* - **Very Large JSON** (323 KB)
|
|
479
|
-
-
|
|
480
|
-
- 1.
|
|
481
|
-
- **
|
|
610
|
+
- 183.33ms
|
|
611
|
+
- 1.42ms
|
|
612
|
+
- **129.0x**
|
|
482
613
|
|
|
483
614
|
**Usage with Rust Extension:**
|
|
484
615
|
|
|
@@ -508,7 +639,7 @@ For other platforms, the pure Python version is used automatically.
|
|
|
508
639
|
Performance Benchmarks
|
|
509
640
|
^^^^^^^^^^^^^^^^^^^^^^
|
|
510
641
|
|
|
511
|
-
Comprehensive benchmarks comparing all implementations (Apple Silicon,
|
|
642
|
+
Comprehensive benchmarks comparing all implementations (Apple Silicon, macOS 26.4.1, Python 3.14.4, April 2026):
|
|
512
643
|
|
|
513
644
|
.. list-table::
|
|
514
645
|
:header-rows: 1
|
|
@@ -521,40 +652,40 @@ Comprehensive benchmarks comparing all implementations (Apple Silicon, January 2
|
|
|
521
652
|
- Zig
|
|
522
653
|
- Best
|
|
523
654
|
* - **Small** (47B)
|
|
524
|
-
-
|
|
525
|
-
-
|
|
526
|
-
- 4.
|
|
527
|
-
-
|
|
528
|
-
- Rust (
|
|
655
|
+
- 31.49µs
|
|
656
|
+
- 0.55µs
|
|
657
|
+
- 4.09ms
|
|
658
|
+
- 2.02ms
|
|
659
|
+
- Rust (56.8x)
|
|
529
660
|
* - **Medium** (3.2KB)
|
|
530
|
-
-
|
|
531
|
-
-
|
|
532
|
-
- 4.
|
|
533
|
-
-
|
|
534
|
-
- Rust (
|
|
661
|
+
- 1.69ms
|
|
662
|
+
- 16.15µs
|
|
663
|
+
- 4.07ms
|
|
664
|
+
- 2.09ms
|
|
665
|
+
- Rust (105.0x)
|
|
535
666
|
* - **Large** (32KB)
|
|
536
|
-
-
|
|
537
|
-
-
|
|
538
|
-
-
|
|
539
|
-
-
|
|
540
|
-
- Rust (
|
|
667
|
+
- 17.97ms
|
|
668
|
+
- 168.21µs
|
|
669
|
+
- 4.10ms
|
|
670
|
+
- 2.42ms
|
|
671
|
+
- Rust (106.8x)
|
|
541
672
|
* - **Very Large** (323KB)
|
|
542
|
-
-
|
|
543
|
-
-
|
|
544
|
-
- 4.
|
|
545
|
-
-
|
|
546
|
-
-
|
|
673
|
+
- 183.33ms
|
|
674
|
+
- 1.42ms
|
|
675
|
+
- 4.20ms
|
|
676
|
+
- 5.12ms
|
|
677
|
+
- Rust (129.0x)
|
|
547
678
|
|
|
548
679
|
**Key Findings:**
|
|
549
680
|
|
|
550
|
-
- **Rust extension**:
|
|
551
|
-
- **Go CLI**:
|
|
552
|
-
- **Zig CLI**:
|
|
681
|
+
- **Rust extension**: 57-129x faster than Python, zero process overhead (best for Python users)
|
|
682
|
+
- **Go CLI**: 43.6x faster for very large files (300KB+), but has ~4ms startup overhead
|
|
683
|
+
- **Zig CLI**: 7.4x faster for large files and 35.8x faster for very large files, with ~2ms startup overhead
|
|
553
684
|
|
|
554
685
|
**Recommendation by Use Case:**
|
|
555
686
|
|
|
556
|
-
- **Python library calls**: Use ``pip install json2xml[fast]`` (Rust,
|
|
557
|
-
- **Large file CLI processing**: Use `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_
|
|
687
|
+
- **Python library calls**: Use ``pip install json2xml[fast]`` (Rust, up to 129x faster)
|
|
688
|
+
- **Large file CLI processing**: Use `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_ or `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_ depending on your workload
|
|
558
689
|
- **Pure Python required**: Use ``pip install json2xml``
|
|
559
690
|
|
|
560
691
|
For detailed benchmarks, see `BENCHMARKS.md <https://github.com/vinitkumar/json2xml/blob/master/BENCHMARKS.md>`_.
|
|
@@ -565,13 +696,12 @@ Other Implementations
|
|
|
565
696
|
|
|
566
697
|
This library is also available in other languages:
|
|
567
698
|
|
|
568
|
-
- **Rust**: `json2xml-rs <https://pypi.org/project/json2xml-rs/>`_ -
|
|
569
|
-
- **Go**: `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_ -
|
|
570
|
-
- **Zig**: `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_ -
|
|
699
|
+
- **Rust**: `json2xml-rs <https://pypi.org/project/json2xml-rs/>`_ - up to 129x faster, Python extension via PyO3
|
|
700
|
+
- **Go**: `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_ - 43.6x faster for very large files, native CLI
|
|
701
|
+
- **Zig**: `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_ - 35.8x faster for very large files, native CLI
|
|
571
702
|
|
|
572
703
|
|
|
573
704
|
Help and Support to maintain this project
|
|
574
705
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
575
706
|
|
|
576
707
|
- You can sponsor my work for this plugin here: https://github.com/sponsors/vinitkumar/
|
|
577
|
-
|
|
@@ -18,7 +18,7 @@ json2xml
|
|
|
18
18
|
.. image:: https://codecov.io/gh/vinitkumar/json2xml/branch/master/graph/badge.svg?token=Yt2h55eTL2
|
|
19
19
|
:target: https://codecov.io/gh/vinitkumar/json2xml
|
|
20
20
|
|
|
21
|
-
json2xml is a Python library
|
|
21
|
+
json2xml is a Python library and CLI for converting JSON data into XML. It is designed for teams that need predictable XML output, Python-first ergonomics, and a faster native path when conversion speed matters.
|
|
22
22
|
|
|
23
23
|
Documentation: https://json2xml.readthedocs.io.
|
|
24
24
|
|
|
@@ -26,6 +26,137 @@ The library was initially dependent on the `dict2xml` project, but it has now be
|
|
|
26
26
|
|
|
27
27
|
**Looking for a Go version?** Check out `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_, a Go port of this library with identical features and a native CLI tool.
|
|
28
28
|
|
|
29
|
+
Why json2xml?
|
|
30
|
+
^^^^^^^^^^^^^
|
|
31
|
+
|
|
32
|
+
Use json2xml when you need:
|
|
33
|
+
|
|
34
|
+
* A Python library for turning dictionaries, strings, files, or API responses into XML
|
|
35
|
+
* A command-line tool for quick JSON-to-XML conversion from scripts and terminals
|
|
36
|
+
* Optional Rust acceleration with automatic fallback to the pure Python implementation
|
|
37
|
+
* XPath 3.1 compatible output when standards-friendly XML is required
|
|
38
|
+
* A small, focused project with tests, docs, benchmarks, and multiple native implementation experiments
|
|
39
|
+
|
|
40
|
+
Quick Start
|
|
41
|
+
^^^^^^^^^^^
|
|
42
|
+
|
|
43
|
+
Install the Python package:
|
|
44
|
+
|
|
45
|
+
.. code-block:: console
|
|
46
|
+
|
|
47
|
+
pip install json2xml
|
|
48
|
+
|
|
49
|
+
Use it from Python:
|
|
50
|
+
|
|
51
|
+
.. code-block:: python
|
|
52
|
+
|
|
53
|
+
from json2xml import json2xml
|
|
54
|
+
from json2xml.utils import readfromstring
|
|
55
|
+
|
|
56
|
+
data = readfromstring('{"name": "Ada", "language": "Python"}')
|
|
57
|
+
print(json2xml.Json2xml(data).to_xml())
|
|
58
|
+
|
|
59
|
+
Use it from the terminal:
|
|
60
|
+
|
|
61
|
+
.. code-block:: console
|
|
62
|
+
|
|
63
|
+
json2xml-py -s '{"name": "Ada", "language": "Python"}'
|
|
64
|
+
|
|
65
|
+
Install the accelerated path:
|
|
66
|
+
|
|
67
|
+
.. code-block:: console
|
|
68
|
+
|
|
69
|
+
pip install json2xml[fast]
|
|
70
|
+
|
|
71
|
+
Real-world Examples
|
|
72
|
+
^^^^^^^^^^^^^^^^^^^
|
|
73
|
+
|
|
74
|
+
Convert a JSON API response in Python when another system expects XML:
|
|
75
|
+
|
|
76
|
+
.. code-block:: python
|
|
77
|
+
|
|
78
|
+
from json2xml import json2xml
|
|
79
|
+
|
|
80
|
+
api_response = {"user": {"id": 7, "name": "Ada"}, "active": True}
|
|
81
|
+
print(json2xml.Json2xml(api_response, pretty=False).to_xml().decode("utf-8"))
|
|
82
|
+
|
|
83
|
+
Output:
|
|
84
|
+
|
|
85
|
+
.. code-block:: xml
|
|
86
|
+
|
|
87
|
+
<?xml version="1.0" encoding="UTF-8" ?><all><user type="dict"><id type="int">7</id><name type="str">Ada</name></user><active type="bool">true</active></all>
|
|
88
|
+
|
|
89
|
+
Convert a local JSON export from the shell:
|
|
90
|
+
|
|
91
|
+
.. code-block:: console
|
|
92
|
+
|
|
93
|
+
cat > orders.json <<'JSON'
|
|
94
|
+
{"orders":[{"id":"A100","total":19.99},{"id":"A101","total":5.5}]}
|
|
95
|
+
JSON
|
|
96
|
+
json2xml-py --no-pretty --no-type orders.json
|
|
97
|
+
|
|
98
|
+
Output:
|
|
99
|
+
|
|
100
|
+
.. code-block:: xml
|
|
101
|
+
|
|
102
|
+
<?xml version="1.0" encoding="UTF-8" ?><all><orders><item><id>A100</id><total>19.99</total></item><item><id>A101</id><total>5.5</total></item></orders></all>
|
|
103
|
+
|
|
104
|
+
Convert stdin in a shell pipeline:
|
|
105
|
+
|
|
106
|
+
.. code-block:: console
|
|
107
|
+
|
|
108
|
+
printf '%s\n' '{"event":"deploy","status":"ok"}' | json2xml-py --no-pretty --no-type -
|
|
109
|
+
|
|
110
|
+
Output:
|
|
111
|
+
|
|
112
|
+
.. code-block:: xml
|
|
113
|
+
|
|
114
|
+
<?xml version="1.0" encoding="UTF-8" ?><all><event>deploy</event><status>ok</status></all>
|
|
115
|
+
|
|
116
|
+
Performance Snapshot
|
|
117
|
+
^^^^^^^^^^^^^^^^^^^^
|
|
118
|
+
|
|
119
|
+
The optional Rust extension is the fastest path for Python callers because it avoids process startup overhead and falls back to pure Python when a feature is not supported natively.
|
|
120
|
+
|
|
121
|
+
.. list-table::
|
|
122
|
+
:header-rows: 1
|
|
123
|
+
:widths: 30 20 20 15
|
|
124
|
+
|
|
125
|
+
* - Test Case
|
|
126
|
+
- Pure Python
|
|
127
|
+
- Rust Extension
|
|
128
|
+
- Speedup
|
|
129
|
+
* - **Small JSON** (47 bytes)
|
|
130
|
+
- 31.49µs
|
|
131
|
+
- 0.55µs
|
|
132
|
+
- **56.8x**
|
|
133
|
+
* - **Medium JSON** (3.2 KB)
|
|
134
|
+
- 1.69ms
|
|
135
|
+
- 16.15µs
|
|
136
|
+
- **105.0x**
|
|
137
|
+
* - **Large JSON** (32 KB)
|
|
138
|
+
- 17.97ms
|
|
139
|
+
- 168.21µs
|
|
140
|
+
- **106.8x**
|
|
141
|
+
* - **Very Large JSON** (323 KB)
|
|
142
|
+
- 183.33ms
|
|
143
|
+
- 1.42ms
|
|
144
|
+
- **129.0x**
|
|
145
|
+
|
|
146
|
+
See `BENCHMARKS.md <https://github.com/vinitkumar/json2xml/blob/master/BENCHMARKS.md>`_ for the full Python, Rust, Go, and Zig comparison.
|
|
147
|
+
|
|
148
|
+
Project Roadmap
|
|
149
|
+
^^^^^^^^^^^^^^^
|
|
150
|
+
|
|
151
|
+
The next phase of json2xml is focused on making the project easier to adopt, benchmark, and contribute to:
|
|
152
|
+
|
|
153
|
+
* Improve examples for common API, file, and CLI workflows
|
|
154
|
+
* Add clearer contribution paths for docs, CLI polish, and benchmark coverage
|
|
155
|
+
* Keep comparing Python, Rust, Go, and Zig implementations with reproducible benchmarks
|
|
156
|
+
* Continue hardening the Rust extension fallback behavior across platforms
|
|
157
|
+
|
|
158
|
+
See `ROADMAP.md <https://github.com/vinitkumar/json2xml/blob/master/ROADMAP.md>`_ for more detail.
|
|
159
|
+
|
|
29
160
|
|
|
30
161
|
|
|
31
162
|
Architecture Diagram
|
|
@@ -43,7 +174,7 @@ Installation
|
|
|
43
174
|
|
|
44
175
|
pip install json2xml
|
|
45
176
|
|
|
46
|
-
**With Native Rust Acceleration (up to
|
|
177
|
+
**With Native Rust Acceleration (up to 129x faster)**
|
|
47
178
|
|
|
48
179
|
For maximum performance, install the optional Rust extension:
|
|
49
180
|
|
|
@@ -55,7 +186,7 @@ For maximum performance, install the optional Rust extension:
|
|
|
55
186
|
# Or install the Rust extension separately
|
|
56
187
|
pip install json2xml-rs
|
|
57
188
|
|
|
58
|
-
The Rust extension provides **
|
|
189
|
+
The Rust extension provides **57-129x faster** conversion compared to pure Python in the latest benchmark. It's automatically used when available, with seamless fallback to pure Python.
|
|
59
190
|
|
|
60
191
|
**As a CLI Tool**
|
|
61
192
|
|
|
@@ -301,7 +432,7 @@ Using tools directly:
|
|
|
301
432
|
|
|
302
433
|
**Rust Extension Development**
|
|
303
434
|
|
|
304
|
-
The optional Rust extension (``json2xml-rs``) provides up to
|
|
435
|
+
The optional Rust extension (``json2xml-rs``) provides up to 129x faster performance in the latest benchmark. To develop or build the Rust extension:
|
|
305
436
|
|
|
306
437
|
Prerequisites:
|
|
307
438
|
|
|
@@ -428,21 +559,21 @@ For users who need maximum performance within Python, json2xml includes an optio
|
|
|
428
559
|
- Rust Extension
|
|
429
560
|
- Speedup
|
|
430
561
|
* - **Small JSON** (47 bytes)
|
|
431
|
-
-
|
|
432
|
-
-
|
|
433
|
-
- **
|
|
562
|
+
- 31.49µs
|
|
563
|
+
- 0.55µs
|
|
564
|
+
- **56.8x**
|
|
434
565
|
* - **Medium JSON** (3.2 KB)
|
|
435
|
-
-
|
|
436
|
-
- 15µs
|
|
437
|
-
- **
|
|
566
|
+
- 1.69ms
|
|
567
|
+
- 16.15µs
|
|
568
|
+
- **105.0x**
|
|
438
569
|
* - **Large JSON** (32 KB)
|
|
439
|
-
-
|
|
440
|
-
-
|
|
441
|
-
- **
|
|
570
|
+
- 17.97ms
|
|
571
|
+
- 168.21µs
|
|
572
|
+
- **106.8x**
|
|
442
573
|
* - **Very Large JSON** (323 KB)
|
|
443
|
-
-
|
|
444
|
-
- 1.
|
|
445
|
-
- **
|
|
574
|
+
- 183.33ms
|
|
575
|
+
- 1.42ms
|
|
576
|
+
- **129.0x**
|
|
446
577
|
|
|
447
578
|
**Usage with Rust Extension:**
|
|
448
579
|
|
|
@@ -472,7 +603,7 @@ For other platforms, the pure Python version is used automatically.
|
|
|
472
603
|
Performance Benchmarks
|
|
473
604
|
^^^^^^^^^^^^^^^^^^^^^^
|
|
474
605
|
|
|
475
|
-
Comprehensive benchmarks comparing all implementations (Apple Silicon,
|
|
606
|
+
Comprehensive benchmarks comparing all implementations (Apple Silicon, macOS 26.4.1, Python 3.14.4, April 2026):
|
|
476
607
|
|
|
477
608
|
.. list-table::
|
|
478
609
|
:header-rows: 1
|
|
@@ -485,40 +616,40 @@ Comprehensive benchmarks comparing all implementations (Apple Silicon, January 2
|
|
|
485
616
|
- Zig
|
|
486
617
|
- Best
|
|
487
618
|
* - **Small** (47B)
|
|
488
|
-
-
|
|
489
|
-
-
|
|
490
|
-
- 4.
|
|
491
|
-
-
|
|
492
|
-
- Rust (
|
|
619
|
+
- 31.49µs
|
|
620
|
+
- 0.55µs
|
|
621
|
+
- 4.09ms
|
|
622
|
+
- 2.02ms
|
|
623
|
+
- Rust (56.8x)
|
|
493
624
|
* - **Medium** (3.2KB)
|
|
494
|
-
-
|
|
495
|
-
-
|
|
496
|
-
- 4.
|
|
497
|
-
-
|
|
498
|
-
- Rust (
|
|
625
|
+
- 1.69ms
|
|
626
|
+
- 16.15µs
|
|
627
|
+
- 4.07ms
|
|
628
|
+
- 2.09ms
|
|
629
|
+
- Rust (105.0x)
|
|
499
630
|
* - **Large** (32KB)
|
|
500
|
-
-
|
|
501
|
-
-
|
|
502
|
-
-
|
|
503
|
-
-
|
|
504
|
-
- Rust (
|
|
631
|
+
- 17.97ms
|
|
632
|
+
- 168.21µs
|
|
633
|
+
- 4.10ms
|
|
634
|
+
- 2.42ms
|
|
635
|
+
- Rust (106.8x)
|
|
505
636
|
* - **Very Large** (323KB)
|
|
506
|
-
-
|
|
507
|
-
-
|
|
508
|
-
- 4.
|
|
509
|
-
-
|
|
510
|
-
-
|
|
637
|
+
- 183.33ms
|
|
638
|
+
- 1.42ms
|
|
639
|
+
- 4.20ms
|
|
640
|
+
- 5.12ms
|
|
641
|
+
- Rust (129.0x)
|
|
511
642
|
|
|
512
643
|
**Key Findings:**
|
|
513
644
|
|
|
514
|
-
- **Rust extension**:
|
|
515
|
-
- **Go CLI**:
|
|
516
|
-
- **Zig CLI**:
|
|
645
|
+
- **Rust extension**: 57-129x faster than Python, zero process overhead (best for Python users)
|
|
646
|
+
- **Go CLI**: 43.6x faster for very large files (300KB+), but has ~4ms startup overhead
|
|
647
|
+
- **Zig CLI**: 7.4x faster for large files and 35.8x faster for very large files, with ~2ms startup overhead
|
|
517
648
|
|
|
518
649
|
**Recommendation by Use Case:**
|
|
519
650
|
|
|
520
|
-
- **Python library calls**: Use ``pip install json2xml[fast]`` (Rust,
|
|
521
|
-
- **Large file CLI processing**: Use `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_
|
|
651
|
+
- **Python library calls**: Use ``pip install json2xml[fast]`` (Rust, up to 129x faster)
|
|
652
|
+
- **Large file CLI processing**: Use `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_ or `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_ depending on your workload
|
|
522
653
|
- **Pure Python required**: Use ``pip install json2xml``
|
|
523
654
|
|
|
524
655
|
For detailed benchmarks, see `BENCHMARKS.md <https://github.com/vinitkumar/json2xml/blob/master/BENCHMARKS.md>`_.
|
|
@@ -529,13 +660,12 @@ Other Implementations
|
|
|
529
660
|
|
|
530
661
|
This library is also available in other languages:
|
|
531
662
|
|
|
532
|
-
- **Rust**: `json2xml-rs <https://pypi.org/project/json2xml-rs/>`_ -
|
|
533
|
-
- **Go**: `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_ -
|
|
534
|
-
- **Zig**: `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_ -
|
|
663
|
+
- **Rust**: `json2xml-rs <https://pypi.org/project/json2xml-rs/>`_ - up to 129x faster, Python extension via PyO3
|
|
664
|
+
- **Go**: `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_ - 43.6x faster for very large files, native CLI
|
|
665
|
+
- **Zig**: `json2xml-zig <https://github.com/vinitkumar/json2xml-zig>`_ - 35.8x faster for very large files, native CLI
|
|
535
666
|
|
|
536
667
|
|
|
537
668
|
Help and Support to maintain this project
|
|
538
669
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
539
670
|
|
|
540
671
|
- You can sponsor my work for this plugin here: https://github.com/sponsors/vinitkumar/
|
|
541
|
-
|