aoiroaoino / play-json-xml

It converts between play-json and xml like json4s.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

play-json-xml Build Status

It converts between play-json and xml like json4s.

Install

Builds are available for Scala 2.10.x, 2.11.x and for 2.12.x. The main line of development of play-json-xml is 2.12.1.

libraryDependencies += "org.micchon" %% "play-json-xml" % "0.1.0"

Useage

If you want to convert xml to json,

import org.micchon.playjsonxml.Xml.toJson
import org.micchon.playjsonxml.Implicits._
import play.api.libs.json._

import scala.xml._

val xml =
  <money>
    <yen>
      <price>100</price>
    </yen>
    <dol>
      <price>110</price>
    </dol>
  </money>

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,

import org.micchon.playjsonxml.Xml.toXml
import org.micchon.playjsonxml.Implicits._
import play.api.libs.json._

val json = Json.parse(
  """
    |{
    |   "fruits":{
    |      "fruit":[
    |         {
    |            "name":"banana",
    |            "price":1000,
    |            "season":true,
    |            "delicious":true
    |         },
    |         {
    |            "name":"strowberry",
    |            "price":3000,
    |            "season":false,
    |            "delicious":true
    |         }
    |      ]
    |   }
    |}
  """.stripMargin)
  
toXml(json) == // or json.toXml
  <fruits><fruit><name>banana</name><price>1000</price><season>true</season><delicious>true</delicious></fruit><fruit><name>strowberry</name><price>3000</price><season>false</season><delicious>true</delicious></fruit></fruits>

About

It converts between play-json and xml like json4s.

License:Apache License 2.0


Languages

Language:Scala 100.0%