Hi,
I just quickly spiked this and following works on my local branch:
scala> val xml =
<foos>
<foo>
<id>1</id>
<name>Harry</name>
</foo>
<foo>
<id>2</id>
<name>David</name>
</foo>
</foos>
scala> val json = toJson(xml)
scala> compact(render(json))
{"foos":{"foo":[{"id":"1","name":"Harry"},{"id":"2","name":"David"}]}}
scala> val json2 = json map {
case JField("id", JString(s)) => JField("id", JInt(s.toInt))
case x => x
}
scala> compact(render(json2))
{"foos":{"foo":[{"id":1,"name":"Harry"},{"id":2,"name":"David"}]}}
This could be quite useful addition. However, I have at least one
concern. What kind of processing instructions will eventually be
needed for this to be generic enough? For instance, lets change the
example XML to:
<foos>
<foo>
<id>1</id>
<name>Harry</name>
</foo>
</foos>
This would still be valid when validating against original XML's DTD,
but the generated JSON structure would be something quite different
(no arrays):
{"foos":{"foo":{"id":1,"name":"Harry"}}}
Cheers Joni