json2xml 5.0.4__tar.gz → 5.3.1__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.
Files changed (47) hide show
  1. {json2xml-5.0.4 → json2xml-5.3.1}/HISTORY.rst +35 -0
  2. json2xml-5.3.1/LICENSE +201 -0
  3. json2xml-5.3.1/PKG-INFO +297 -0
  4. {json2xml-5.0.4 → json2xml-5.3.1}/README.rst +79 -20
  5. {json2xml-5.0.4 → json2xml-5.3.1}/json2xml/__init__.py +1 -1
  6. {json2xml-5.0.4 → json2xml-5.3.1}/json2xml/dicttoxml.py +141 -16
  7. {json2xml-5.0.4 → json2xml-5.3.1}/json2xml/json2xml.py +6 -3
  8. {json2xml-5.0.4 → json2xml-5.3.1}/json2xml/utils.py +0 -1
  9. json2xml-5.3.1/json2xml.egg-info/PKG-INFO +297 -0
  10. {json2xml-5.0.4 → json2xml-5.3.1}/json2xml.egg-info/SOURCES.txt +4 -2
  11. json2xml-5.3.1/json2xml.egg-info/requires.txt +10 -0
  12. json2xml-5.3.1/pyproject.toml +77 -0
  13. json2xml-5.3.1/requirements.in +3 -0
  14. {json2xml-5.0.4 → json2xml-5.3.1}/setup.cfg +1 -9
  15. json2xml-5.3.1/setup.py +8 -0
  16. json2xml-5.3.1/tests/conftest.py +80 -0
  17. json2xml-5.3.1/tests/test_dict2xml.py +1144 -0
  18. {json2xml-5.0.4 → json2xml-5.3.1}/tests/test_json2xml.py +131 -30
  19. json2xml-5.3.1/tests/test_missing_coverage.py +405 -0
  20. json2xml-5.3.1/tests/test_utils.py +309 -0
  21. json2xml-5.0.4/LICENSE +0 -16
  22. json2xml-5.0.4/PKG-INFO +0 -670
  23. json2xml-5.0.4/json2xml.egg-info/PKG-INFO +0 -670
  24. json2xml-5.0.4/json2xml.egg-info/not-zip-safe +0 -1
  25. json2xml-5.0.4/json2xml.egg-info/requires.txt +0 -2
  26. json2xml-5.0.4/pyproject.toml +0 -19
  27. json2xml-5.0.4/requirements.in +0 -3
  28. json2xml-5.0.4/setup.py +0 -53
  29. json2xml-5.0.4/tests/test_dict2xml.py +0 -395
  30. {json2xml-5.0.4 → json2xml-5.3.1}/AUTHORS.rst +0 -0
  31. {json2xml-5.0.4 → json2xml-5.3.1}/CONTRIBUTING.rst +0 -0
  32. {json2xml-5.0.4 → json2xml-5.3.1}/MANIFEST.in +0 -0
  33. {json2xml-5.0.4 → json2xml-5.3.1}/docs/Makefile +0 -0
  34. {json2xml-5.0.4 → json2xml-5.3.1}/docs/authors.rst +0 -0
  35. {json2xml-5.0.4 → json2xml-5.3.1}/docs/conf.py +2 -2
  36. {json2xml-5.0.4 → json2xml-5.3.1}/docs/contributing.rst +0 -0
  37. {json2xml-5.0.4 → json2xml-5.3.1}/docs/history.rst +0 -0
  38. {json2xml-5.0.4 → json2xml-5.3.1}/docs/index.rst +0 -0
  39. {json2xml-5.0.4 → json2xml-5.3.1}/docs/installation.rst +0 -0
  40. {json2xml-5.0.4 → json2xml-5.3.1}/docs/json2xml.rst +0 -0
  41. {json2xml-5.0.4 → json2xml-5.3.1}/docs/make.bat +0 -0
  42. {json2xml-5.0.4 → json2xml-5.3.1}/docs/modules.rst +0 -0
  43. {json2xml-5.0.4 → json2xml-5.3.1}/docs/readme.rst +0 -0
  44. {json2xml-5.0.4 → json2xml-5.3.1}/docs/usage.rst +0 -0
  45. {json2xml-5.0.4 → json2xml-5.3.1}/json2xml.egg-info/dependency_links.txt +0 -0
  46. {json2xml-5.0.4 → json2xml-5.3.1}/json2xml.egg-info/top_level.txt +0 -0
  47. {json2xml-5.0.4 → json2xml-5.3.1}/tests/__init__.py +0 -0
@@ -1,6 +1,41 @@
1
1
  History
2
2
  =======
3
3
 
4
+ 5.3.0 / 2025-12-08
5
+ ==================
6
+
7
+ * chore: bump version
8
+ * fix: bump version
9
+ * fix: should be all green now
10
+ * lint: fix ossues with lines
11
+ * feat: add missing tests
12
+ * feat: add xPath support
13
+ * chore(deps): bump starlette from 0.47.2 to 0.49.1 in /docs (#257)
14
+ * feat: improvements to ruff and new python 3.15 (#255)
15
+ * Modernize Python code to 3.10+ with pyupgrade (#254)
16
+ * check arm build ubuntu (#253)
17
+ * Remove duplicate typecheck job from pythonpackage workflow
18
+ * Migrate from mypy to ty for type checking (#252)
19
+ * Add Python 3.14t (freethreaded) to testing matrix (#251)
20
+ * prod release (#249)
21
+ * bump python to latest rc2
22
+ * fix: switch to release candidate 2 of Python 3.14
23
+
24
+ 5.2.0 / 2025-07-21
25
+ ==================
26
+
27
+ * chore: version bump to 5.2.0
28
+ * chore(deps): bump urllib3 from 2.3.0 to 2.5.0 (#244)
29
+ * security: Fix Jinja2 and py library vulnerabilities (#243)
30
+ * Update LICENSE
31
+
32
+ 5.0.5 / 2024-08-31
33
+ ==================
34
+
35
+ * tests (json2xml): add test for encoding
36
+ * fix missing encoding indication on pretty mode (#213)
37
+ * chore(deps): bump webob from 1.8.7 to 1.8.8 in /docs (#212)
38
+
4
39
  5.0.4 / 2024-08-08
5
40
  ==================
6
41
 
json2xml-5.3.1/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2025] [Vinit Kumar]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,297 @@
1
+ Metadata-Version: 2.4
2
+ Name: json2xml
3
+ Version: 5.3.1
4
+ Summary: Simple Python Library to convert JSON to XML
5
+ Author-email: Vinit Kumar <mail@vinitkumar.me>
6
+ License: Apache Software License 2.0
7
+ Project-URL: Homepage, https://github.com/vinitkumar/json2xml
8
+ Keywords: json2xml
9
+ Classifier: Development Status :: 6 - Mature
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: Implementation :: CPython
19
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/x-rst
23
+ License-File: LICENSE
24
+ License-File: AUTHORS.rst
25
+ Requires-Dist: defusedxml
26
+ Requires-Dist: urllib3
27
+ Requires-Dist: xmltodict>=0.12.0
28
+ Requires-Dist: pytest
29
+ Requires-Dist: pytest-cov
30
+ Requires-Dist: coverage
31
+ Requires-Dist: setuptools
32
+ Provides-Extra: test
33
+ Requires-Dist: pytest>=8.4.1; extra == "test"
34
+ Dynamic: license-file
35
+
36
+ ========
37
+ json2xml
38
+ ========
39
+
40
+ .. image:: https://badge.fury.io/py/json2xml.svg
41
+ .. image:: https://static.pepy.tech/personalized-badge/json2xml?period=total&units=international_system&left_color=blue&right_color=orange&left_text=Downloads
42
+ :target: https://pepy.tech/project/json2xml
43
+
44
+ .. image:: https://github.com/vinitkumar/json2xml/actions/workflows/pythonpackage.yml/badge.svg
45
+ .. image:: https://img.shields.io/pypi/pyversions/json2xml.svg
46
+ .. image:: https://readthedocs.org/projects/json2xml/badge/?version=latest
47
+ :target: https://json2xml.readthedocs.io/en/latest/?badge=latest
48
+ :alt: Documentation Status
49
+ .. image:: https://codecov.io/gh/vinitkumar/json2xml/branch/master/graph/badge.svg?token=Yt2h55eTL2
50
+ :target: https://codecov.io/gh/vinitkumar/json2xml
51
+
52
+ json2xml is a Python library that allows you to convert JSON data into XML format. It's simple, efficient, and easy to use.
53
+
54
+ Documentation: https://json2xml.readthedocs.io.
55
+
56
+ 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.
57
+
58
+
59
+
60
+ Architecture Diagram
61
+ ^^^^^^^^^^^^^^^^^^^^
62
+
63
+ .. image:: ./diagram.png
64
+
65
+
66
+ Features
67
+ ^^^^^^^^
68
+
69
+ json2xml supports the following features:
70
+
71
+ * Conversion from a `json` string to XML
72
+ * Conversion from a `json` file to XML
73
+ * Conversion from an API that emits `json` data to XML
74
+ * Compliant with the `json-to-xml` function specification from `XPath 3.1 <https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml>`_
75
+
76
+ Usage
77
+ ^^^^^
78
+
79
+ You can use the json2xml library in the following ways:
80
+
81
+
82
+ .. code-block:: python
83
+
84
+ from json2xml import json2xml
85
+ from json2xml.utils import readfromurl, readfromstring, readfromjson
86
+
87
+ # Convert JSON data from a URL to XML
88
+ data = readfromurl("https://api.publicapis.org/entries")
89
+ print(json2xml.Json2xml(data).to_xml())
90
+
91
+ # Convert a JSON string to XML
92
+ data = readfromstring(
93
+ '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
94
+ )
95
+ print(json2xml.Json2xml(data).to_xml())
96
+
97
+ # Convert a JSON file to XML
98
+ data = readfromjson("examples/licht.json")
99
+ print(json2xml.Json2xml(data).to_xml())
100
+
101
+
102
+ Custom Wrappers and Indentation
103
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104
+
105
+ By default, a wrapper `all` and pretty `True` is set. However, you can easily change this in your code like this:
106
+
107
+ .. code-block:: python
108
+
109
+ from json2xml import json2xml
110
+ from json2xml.utils import readfromurl, readfromstring, readfromjson
111
+
112
+ data = readfromstring(
113
+ '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
114
+ )
115
+ print(json2xml.Json2xml(data, wrapper="all", pretty=True).to_xml())
116
+
117
+
118
+ Outputs this:
119
+
120
+ .. code-block:: xml
121
+
122
+ <?xml version="1.0" encoding="UTF-8"?>
123
+ <all>
124
+ <login type="str">mojombo</login>
125
+ <id type="int">1</id>
126
+ <avatar_url type="str">https://avatars0.githubusercontent.com/u/1?v=4</avatar_url>
127
+ </all>
128
+
129
+ Omit List item
130
+ ^^^^^^^^^^^^^^
131
+
132
+ Assume the following json input
133
+
134
+ .. code-block:: json
135
+
136
+ {
137
+ "my_items": [
138
+ { "my_item": { "id": 1 } },
139
+ { "my_item": { "id": 2 } }
140
+ ],
141
+ "my_str_items": ["a", "b"]
142
+ }
143
+
144
+ By default, items in an array are wrapped in <item></item>.
145
+
146
+ Default output:
147
+
148
+ .. code-block:: xml
149
+
150
+ <?xml version="1.0" ?>
151
+ <all>
152
+ <my_items type="list">
153
+ <item type="dict">
154
+ <my_item type="dict">
155
+ <id type="int">1</id>
156
+ </my_item>
157
+ </item>
158
+ <item type="dict">
159
+ <my_item type="dict">
160
+ <id type="int">2</id>
161
+ </my_item>
162
+ </item>
163
+ </my_items>
164
+ <my_str_items type="list">
165
+ <item type="str">a</item>
166
+ <item type="str">b</item>
167
+ </my_str_items>
168
+ <empty type="list"/>
169
+ </all>
170
+
171
+ However, you can change this behavior using the item_wrap property like this:
172
+
173
+ .. code-block:: python
174
+
175
+ from json2xml import json2xml
176
+ from json2xml.utils import readfromurl, readfromstring, readfromjson
177
+
178
+ data = readfromstring('{"my_items":[{"my_item":{"id":1} },{"my_item":{"id":2} }],"my_str_items":["a","b"]}')
179
+ print(json2xml.Json2xml(data, item_wrap=False).to_xml())
180
+
181
+ Outputs this:
182
+
183
+ .. code-block:: xml
184
+
185
+ <?xml version="1.0" ?>
186
+ <all>
187
+ <my_items type="list">
188
+ <my_item type="dict">
189
+ <id type="int">1</id>
190
+ </my_item>
191
+ <my_item type="dict">
192
+ <id type="int">2</id>
193
+ </my_item>
194
+ </my_items>
195
+ <my_str_items type="str">a</my_str_items>
196
+ <my_str_items type="str">b</my_str_items>
197
+ </all>
198
+
199
+ Optional Attribute Type Support
200
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201
+
202
+ You can also specify if the output XML needs to have type specified or not. Here is the usage:
203
+
204
+ .. code-block:: python
205
+
206
+ from json2xml import json2xml
207
+ from json2xml.utils import readfromurl, readfromstring, readfromjson
208
+
209
+ data = readfromstring(
210
+ '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
211
+ )
212
+ print(json2xml.Json2xml(data, wrapper="all", pretty=True, attr_type=False).to_xml())
213
+
214
+
215
+ Outputs this:
216
+
217
+ .. code-block:: xml
218
+
219
+ <?xml version="1.0" ?>
220
+ <all>
221
+ <login>mojombo</login>
222
+ <id>1</id>
223
+ <avatar_url>https://avatars0.githubusercontent.com/u/1?v=4</avatar_url>
224
+ </all>
225
+
226
+
227
+ XPath 3.1 Compliance Options
228
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229
+
230
+ The library supports the optional `xpath_format` parameter which makes the output compliant with the `json-to-xml` function specification from `XPath 3.1 <https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml>`_. When enabled, the XML output follows the standardized format defined by the W3C specification.
231
+
232
+ .. code-block:: python
233
+
234
+ from json2xml import json2xml
235
+ from json2xml.utils import readfromstring
236
+
237
+ data = readfromstring(
238
+ '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
239
+ )
240
+ # Use xpath_format=True for XPath 3.1 compliant output
241
+ print(json2xml.Json2xml(data, xpath_format=True).to_xml())
242
+
243
+
244
+ The methods are simple and easy to use and there are also checks inside of code to exit cleanly
245
+ in case any of the input(file, string or API URL) returns invalid JSON.
246
+
247
+ Development
248
+ ^^^^^^^^^^^
249
+
250
+ This project uses modern Python development practices. Here's how to set up a development environment:
251
+
252
+ .. code-block:: console
253
+
254
+ # Create and activate virtual environment (using uv - recommended)
255
+ uv venv
256
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
257
+
258
+ # Install dependencies
259
+ uv pip install -r requirements-dev.txt
260
+ uv pip install -e .
261
+
262
+ **Running Tests and Checks**
263
+
264
+ We provide several ways to run tests and quality checks:
265
+
266
+ Using Make (recommended):
267
+
268
+ .. code-block:: console
269
+
270
+ make test # Run tests with coverage
271
+ make lint # Run linting with ruff
272
+ make typecheck # Run type checking with mypy
273
+ make check-all # Run all checks (lint, typecheck, test)
274
+
275
+ Using the development script:
276
+
277
+ .. code-block:: console
278
+
279
+ python dev.py # Run all checks
280
+ python dev.py test # Run tests only
281
+ python dev.py lint # Run linting only
282
+ python dev.py typecheck # Run type checking only
283
+
284
+ Using tools directly:
285
+
286
+ .. code-block:: console
287
+
288
+ pytest --cov=json2xml --cov-report=term -xvs tests -n auto
289
+ ruff check json2xml tests
290
+ mypy json2xml tests
291
+
292
+
293
+ Help and Support to maintain this project
294
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
295
+
296
+ - You can sponsor my work for this plugin here: https://github.com/sponsors/vinitkumar/
297
+
@@ -20,6 +20,14 @@ Documentation: https://json2xml.readthedocs.io.
20
20
 
21
21
  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
+
24
+
25
+ Architecture Diagram
26
+ ^^^^^^^^^^^^^^^^^^^^
27
+
28
+ .. image:: ./diagram.png
29
+
30
+
23
31
  Features
24
32
  ^^^^^^^^
25
33
 
@@ -28,6 +36,7 @@ json2xml supports the following features:
28
36
  * Conversion from a `json` string to XML
29
37
  * Conversion from a `json` file to XML
30
38
  * Conversion from an API that emits `json` data to XML
39
+ * Compliant with the `json-to-xml` function specification from `XPath 3.1 <https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml>`_
31
40
 
32
41
  Usage
33
42
  ^^^^^
@@ -75,7 +84,7 @@ Outputs this:
75
84
 
76
85
  .. code-block:: xml
77
86
 
78
- <?xml version="1.0" ?>
87
+ <?xml version="1.0" encoding="UTF-8"?>
79
88
  <all>
80
89
  <login type="str">mojombo</login>
81
90
  <id type="int">1</id>
@@ -159,41 +168,91 @@ You can also specify if the output XML needs to have type specified or not. Here
159
168
 
160
169
  .. code-block:: python
161
170
 
162
- from json2xml import json2xml
163
- from json2xml.utils import readfromurl, readfromstring, readfromjson
171
+ from json2xml import json2xml
172
+ from json2xml.utils import readfromurl, readfromstring, readfromjson
164
173
 
165
- data = readfromstring(
166
- '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
167
- )
168
- print(json2xml.Json2xml(data, wrapper="all", pretty=True, attr_type=False).to_xml())
174
+ data = readfromstring(
175
+ '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
176
+ )
177
+ print(json2xml.Json2xml(data, wrapper="all", pretty=True, attr_type=False).to_xml())
169
178
 
170
179
 
171
180
  Outputs this:
172
181
 
173
182
  .. code-block:: xml
174
183
 
175
- <?xml version="1.0" ?>
176
- <all>
177
- <login>mojombo</login>
178
- <id>1</id>
179
- <avatar_url>https://avatars0.githubusercontent.com/u/1?v=4</avatar_url>
180
- </all>
184
+ <?xml version="1.0" ?>
185
+ <all>
186
+ <login>mojombo</login>
187
+ <id>1</id>
188
+ <avatar_url>https://avatars0.githubusercontent.com/u/1?v=4</avatar_url>
189
+ </all>
190
+
191
+
192
+ XPath 3.1 Compliance Options
193
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
194
+
195
+ The library supports the optional `xpath_format` parameter which makes the output compliant with the `json-to-xml` function specification from `XPath 3.1 <https://www.w3.org/TR/xpath-functions-31/#func-json-to-xml>`_. When enabled, the XML output follows the standardized format defined by the W3C specification.
196
+
197
+ .. code-block:: python
198
+
199
+ from json2xml import json2xml
200
+ from json2xml.utils import readfromstring
201
+
202
+ data = readfromstring(
203
+ '{"login":"mojombo","id":1,"avatar_url":"https://avatars0.githubusercontent.com/u/1?v=4"}'
204
+ )
205
+ # Use xpath_format=True for XPath 3.1 compliant output
206
+ print(json2xml.Json2xml(data, xpath_format=True).to_xml())
181
207
 
182
208
 
183
209
  The methods are simple and easy to use and there are also checks inside of code to exit cleanly
184
210
  in case any of the input(file, string or API URL) returns invalid JSON.
185
211
 
186
- How to run tests
187
- ^^^^^^^^^^^^^^^^
212
+ Development
213
+ ^^^^^^^^^^^
214
+
215
+ This project uses modern Python development practices. Here's how to set up a development environment:
216
+
217
+ .. code-block:: console
218
+
219
+ # Create and activate virtual environment (using uv - recommended)
220
+ uv venv
221
+ source .venv/bin/activate # On Windows: .venv\Scripts\activate
222
+
223
+ # Install dependencies
224
+ uv pip install -r requirements-dev.txt
225
+ uv pip install -e .
226
+
227
+ **Running Tests and Checks**
228
+
229
+ We provide several ways to run tests and quality checks:
230
+
231
+ Using Make (recommended):
232
+
233
+ .. code-block:: console
234
+
235
+ make test # Run tests with coverage
236
+ make lint # Run linting with ruff
237
+ make typecheck # Run type checking with mypy
238
+ make check-all # Run all checks (lint, typecheck, test)
239
+
240
+ Using the development script:
241
+
242
+ .. code-block:: console
243
+
244
+ python dev.py # Run all checks
245
+ python dev.py test # Run tests only
246
+ python dev.py lint # Run linting only
247
+ python dev.py typecheck # Run type checking only
188
248
 
189
- This is provided by pytest, which is straight forward.
249
+ Using tools directly:
190
250
 
191
251
  .. code-block:: console
192
252
 
193
- virtualenv venv -p $(which python3.9)
194
- pip install -r requirements-dev.txt
195
- python setup.py install
196
- pytest -vv
253
+ pytest --cov=json2xml --cov-report=term -xvs tests -n auto
254
+ ruff check json2xml tests
255
+ mypy json2xml tests
197
256
 
198
257
 
199
258
  Help and Support to maintain this project
@@ -2,5 +2,5 @@
2
2
 
3
3
  __author__ = """Vinit Kumar"""
4
4
  __email__ = "mail@vinitkumar.me"
5
- __version__ = "5.0.4"
5
+ __version__ = "5.3.0"
6
6