Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/3tty0n/play-json-xml
Converting between play-json and xml like json4s.
https://github.com/3tty0n/play-json-xml
json play-json scala xml
Last synced: 2 months ago
JSON representation
Converting between play-json and xml like json4s.
- Host: GitHub
- URL: https://github.com/3tty0n/play-json-xml
- Owner: 3tty0n
- License: apache-2.0
- Created: 2017-03-28T15:48:59.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-09-08T07:48:20.000Z (over 5 years ago)
- Last Synced: 2023-07-07T06:37:57.707Z (over 1 year ago)
- Topics: json, play-json, scala, xml
- Language: Scala
- Homepage:
- Size: 57.6 KB
- Stars: 10
- Watchers: 4
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# play-json-xml
[![Build Status](https://travis-ci.org/3tty0n/play-json-xml.svg?branch=master)](https://travis-ci.org/3tty0n/play-json-xml)
[![Maven Central](https://img.shields.io/maven-central/v/org.micchon/play-json-xml_2.12.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22org.micchon%22%20AND%20a:%22play-json-xml_2.12%22)It converts between play-json and xml like json4s.
## Install
Builds are available for 2.12.x and for 2.13.x. The main line of development of play-json-xml is 2.12.4.
```scala
libraryDependencies += "org.micchon" %% "play-json-xml" % "(version)"
```## Useage
If you want to convert xml to json,
```scala
import play.api.libs.json.Xml
import play.api.libs.json.implicits._
import play.api.libs.json.Jsonimport scala.xml._
val xml =
100
110
Xml.toJson(xml) == // or xml.toJson
JsObject(Seq(
"money" -> JsObject(Seq(
"yen" -> JsObject(Seq("price" -> JsNumber(100))),
"dol" -> JsObject(Seq("price" -> JsNumber(110)))
))
))
```Or, if you want to convert json to xml,
```scala
import play.api.libs.json.Xml
import play.api.libs.json.implicits._
import play.api.libs.json.Jsonval json = Json.parse(
"""
|{
| "fruits":{
| "fruit":[
| {
| "name":"banana",
| "price":1000,
| "season":true,
| "delicious":true
| },
| {
| "name":"strowberry",
| "price":3000,
| "season":false,
| "delicious":true
| }
| ]
| }
|}
""".stripMargin)Xml.toXml(json) == // or json.toXml
banana1000truetruestrowberry3000falsetrue
```