JSON to XML Converter Info - thepoopooman652/proishs-webtools GitHub Wiki
json2xml converts JSON input into XML. It supports uploaded JSON files, pasted JSON, and NDJSON (newline-delimited JSON). The converter provides configurable conventions for mapping JSON keys to XML attributes and text nodes, and it can pretty-print the result or provide a downloadable .xml file.
- Accepts file upload or pasted JSON/NDJSON.
- Handles JSON objects and arrays (top-level arrays become repeated child elements under the root).
- Attribute convention: keys prefixed with a configurable string (default
@) become XML attributes. - Text node convention: a configurable key (default
#text) maps to a node's text content. - Configurable item element name for array elements (default
item). - Preview and download as
.xml.
- Root element name: the XML root element name (default
root). - Attribute prefix: keys starting with this prefix are interpreted as attributes (default
@). - Text key: if an object contains this key, its value becomes the element text content (default
#text). - Item element: when arrays are encountered, elements are wrapped in the named tag for repeated entries (default
item). - Pretty-print: enable formatted XML output.
- Objects map to elements with child elements for each key.
- Numeric arrays produce repeated elements with the configured item element name.
- Keys that start with the attribute prefix become attributes on the element (the attribute name is the remainder of the key).
- The text key sets the element's text content instead of creating a child element.
Input JSON:
{
"person": {
"@id": 123,
"name": "Alice",
"phones": ["123","456"]
}
}Default XML output (with root root):
<root>
<person id="123">
<name>Alice</name>
<phones>
<item>123</item>
<item>456</item>
</phones>
</person>
</root>- This converter uses a deterministic rule set and is not schema-aware. For advanced XML needs (namespaces, attributes with specific types, mixed content), post-processing or a schema-driven approach may be necessary.
- Start a local PHP server in the
json2xmlfolder for testing:
cd 'C:\Users\Administrator\Documents\GitHub\proishs-webtools\converters\json2xml'
php -S 127.0.0.1:8000 -t .- Open
http://127.0.0.1:8000/index.php, paste JSON or upload a.jsonfile, adjust options, then Preview or Download.
- Convert simple objects, arrays, nested structures.
- Validate attribute prefix handling (e.g.,
{"@id":1}->id="1"). - Convert NDJSON input (multiple JSON objects separated by newlines) and verify repeated child elements.
- Toggle pretty-print to verify formatted output.
- The tool can be invoked programmatically by POSTing a file or the
jsontextform field and reading the response (as preview or downloaded file).
- 2025-11-07: Initial implementation:
index.phpconverter and this README.
This README documents the conversion conventions, options and examples for the json2xml converter.