https://github.com/fugerit-org/fj-xml-to-json
Module to convert xml to json and viceversa
https://github.com/fugerit-org/fj-xml-to-json
Last synced: 3 months ago
JSON representation
Module to convert xml to json and viceversa
- Host: GitHub
- URL: https://github.com/fugerit-org/fj-xml-to-json
- Owner: fugerit-org
- License: apache-2.0
- Created: 2023-10-01T09:54:14.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-14T17:12:48.000Z (4 months ago)
- Last Synced: 2025-03-14T18:30:40.222Z (4 months ago)
- Language: Java
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# fj-xml-to-json
Module to convert xml to json and viceversa
[](https://github.com/fugerit-org/fj-xml-to-json/blob/master/CHANGELOG.md)
[](https://mvnrepository.com/artifact/org.fugerit.java/fj-xml-to-json)
[](https://opensource.org/licenses/Apache-2.0)
[](https://github.com/fugerit-org/fj-universe/blob/main/CODE_OF_CONDUCT.md)
[](https://sonarcloud.io/summary/new_code?id=fugerit-org_fj-xml-to-json)
[](https://sonarcloud.io/summary/new_code?id=fugerit-org_fj-xml-to-json)[](https://universe.fugerit.org/src/docs/versions/java11.html)
[](https://universe.fugerit.org/src/docs/versions/java11.html)
[](https://universe.fugerit.org/src/docs/versions/maven3_9.html)
[](https://universe.fugerit.org/src/docs/conventions/index.html)## Quickstart
Sample code to convert from XML to JSON :
```
try ( Reader reader = StreamHelper.resolveReader( path ) ) {
XmlToJsonHandler handler = new XmlToJsonHandler();
JsonNode node = handler.convertToJsonNode(reader);
handler.getMapper().writerWithDefaultPrettyPrinter().writeValue( outputFile , node );
}
```For instance a xml like this :
```
Entry 1
Entry 2
```
Will be converted to :
```
{
"default-list" : "list1",
"_t" : "config",
"_e" : [ {
"id" : "list1",
"_t" : "test-list",
"_e" : [ {
"id" : "entry1",
"_t" : "test-entry",
"_v" : "Entry 1"
}, {
"id" : "entry2",
"_t" : "test-entry",
"_v" : "Entry 2"
} ]
} ]
}
``````
try ( Reader reader = StreamHelper.resolveReader( path );
FileWriter writer = new FileWriter(outputFile) ) {
XmlToJsonHandler handler = new XmlToJsonHandler();
Element root = handler.convertToElement( reader );
DOMIO.writeDOMIndent( root , writer );
}
```See [conversion conventions](src/main/docs/xml_conversion.md) below for more info.
## Documentation
- xml to json conversion conventions (see [xml conversion](src/main/docs/xml_conversion.md))
- [yaml support](src/main/docs/yaml_support.md) documentation