You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The library was initially dependent on the `dict2xml` project, but it has now been integrated into json2xml itself. This has led to cleaner code, the addition of types and tests, and overall improved performance.
22
22
23
+
**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.
24
+
23
25
24
26
25
27
Architecture Diagram
@@ -28,6 +30,30 @@ Architecture Diagram
28
30
.. image:: ./diagram.png
29
31
30
32
33
+
Installation
34
+
^^^^^^^^^^^^
35
+
36
+
**As a Library**
37
+
38
+
.. code-block:: console
39
+
40
+
pip install json2xml
41
+
42
+
**As a CLI Tool**
43
+
44
+
The library includes a command-line tool ``json2xml-py`` that gets installed automatically:
45
+
46
+
.. code-block:: console
47
+
48
+
pip install json2xml
49
+
50
+
# Now you can use it from the command line
51
+
json2xml-py data.json
52
+
json2xml-py -s '{"name": "John", "age": 30}'
53
+
json2xml-py -u https://api.example.com/data.json
54
+
55
+
For CLI options, run ``json2xml-py --help``.
56
+
31
57
Features
32
58
^^^^^^^^
33
59
@@ -37,6 +63,7 @@ json2xml supports the following features:
37
63
* Conversion from a `json` file to XML
38
64
* Conversion from an API that emits `json` data to XML
39
65
* Compliant with the `json-to-xml` function specification from `XPath 3.1 <https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml>`_
66
+
* **Command-line tool** for easy conversion from the terminal
40
67
41
68
Usage
42
69
^^^^^
@@ -255,6 +282,77 @@ Using tools directly:
255
282
mypy json2xml tests
256
283
257
284
285
+
CLI Usage
286
+
^^^^^^^^^
287
+
288
+
The ``json2xml-py`` command-line tool provides an easy way to convert JSON to XML from the terminal.
289
+
290
+
**Basic Examples**
291
+
292
+
.. code-block:: console
293
+
294
+
# Convert a JSON file to XML
295
+
json2xml-py data.json
296
+
297
+
# Convert with custom wrapper element
298
+
json2xml-py -w root data.json
299
+
300
+
# Read JSON from string
301
+
json2xml-py -s '{"name": "John", "age": 30}'
302
+
303
+
# Read from stdin
304
+
cat data.json | json2xml-py -
305
+
306
+
# Output to file
307
+
json2xml-py -o output.xml data.json
308
+
309
+
# Use XPath 3.1 format
310
+
json2xml-py -x data.json
311
+
312
+
# Disable pretty printing and type attributes
313
+
json2xml-py --no-pretty --no-type data.json
314
+
315
+
**CLI Options**
316
+
317
+
.. code-block:: text
318
+
319
+
Input Options:
320
+
-u, --url string Read JSON from URL
321
+
-s, --string string Read JSON from string
322
+
[input-file] Read JSON from file (use - for stdin)
323
+
324
+
Output Options:
325
+
-o, --output string Output file (default: stdout)
326
+
327
+
Conversion Options:
328
+
-w, --wrapper string Wrapper element name (default "all")
329
+
-r, --root Include root element (default true)
330
+
-p, --pretty Pretty print output (default true)
331
+
-t, --type Include type attributes (default true)
332
+
-i, --item-wrap Wrap list items in <item> elements (default true)
333
+
-x, --xpath Use XPath 3.1 json-to-xml format
334
+
-c, --cdata Wrap string values in CDATA sections
335
+
-l, --list-headers Repeat headers for each list item
336
+
337
+
Other Options:
338
+
-v, --version Show version information
339
+
-h, --help Show help message
340
+
341
+
342
+
Go Version
343
+
^^^^^^^^^^
344
+
345
+
A Go port of this library is available at `json2xml-go <https://github.com/vinitkumar/json2xml-go>`_.
346
+
347
+
**Install the Go CLI:**
348
+
349
+
.. code-block:: console
350
+
351
+
go install github.com/vinitkumar/json2xml-go/cmd/json2xml@latest
352
+
353
+
The Go version provides the same features and a native compiled binary for maximum performance.
0 commit comments