Skip to content

Commit 9abeba0

Browse files
committed
docs: add CLI usage and cross-reference to Go version
- Add Installation section with pip install instructions - Add CLI Usage section with examples and all options - Add reference to json2xml-go (Go port) with install instructions - Document command-line tool feature
1 parent 1bfc7ca commit 9abeba0

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

README.rst

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Documentation: https://json2xml.readthedocs.io.
2020

2121
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.
2222

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+
2325

2426

2527
Architecture Diagram
@@ -28,6 +30,30 @@ Architecture Diagram
2830
.. image:: ./diagram.png
2931

3032

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+
3157
Features
3258
^^^^^^^^
3359

@@ -37,6 +63,7 @@ json2xml supports the following features:
3763
* Conversion from a `json` file to XML
3864
* Conversion from an API that emits `json` data to XML
3965
* 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
4067

4168
Usage
4269
^^^^^
@@ -255,6 +282,77 @@ Using tools directly:
255282
mypy json2xml tests
256283
257284
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.
354+
355+
258356
Help and Support to maintain this project
259357
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
260358

0 commit comments

Comments
 (0)