README.md

# xmljson 

Converts XML to JSON and vice versa. The JSON schema used is [badgerfish](http://www.sklar.com/badgerfish/). Badgerfish is used because it is mostly lossless, although there are rare cases where information could be lost in the conversion.

[![Package Version](https://img.shields.io/hexpm/v/xmljson)](https://hex.pm/packages/xmljson)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/xmljson/)

```sh
gleam add xmljson
```
```gleam
import xmljson

pub fn main() {
  let input = "<alice>bob</alice>"

  let json = xmljson.to_json(input)
  // "{ \"alice\": { \"$\" : \"bob\" } }"
  xmljson.to_xml_fragment(json)
  // "<alice>bob</alice>"

  // Multiple values become a list
  let input = "<alice><bob>charlie</bob><bob>david</bob></alice>"
  let json = xmljson.to_json(input)
  // "{ \"alice\": { \"bob\" : [{\"$\": \"charlie\" }, {\"$\": \"david\" }] } }"

  // Attributes are labelled with an @
  let input = "<alice charlie=\"david\">bob</alice>"
  let json = xmljson.to_json(input)
  // "{ \"alice\": { \"$\" : \"bob\", \"@charlie\" : \"david\" } }"
}
```

Further documentation can be found at <https://hexdocs.pm/xmljson>.

## Development

```sh
gleam run   # Run the project
gleam test  # Run the tests
```