<?xml version="1.0" encoding="UTF-8"?>
<json:object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx"
xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd">
<json:string name="name">John Smith</json:string>
<json:object name="address">
<json:string name="streetAddress">21 2nd Street</json:string>
<json:string name="city">New York</json:string>
<json:string name="state">NY</json:string>
<json:number name="postalCode">10021</json:number>
</json:object>
<json:array name="phoneNumbers">
<json:string>212 555-1111</json:string>
<json:string>212 555-2222</json:string>
</json:array>
<json:null name="additionalInfo"/>
<json:boolean name="remote">false</json:boolean>
<json:number name="height">62.4</json:number>
<json:string name="ficoScore"> > 640</json:string>
</json:object>
translated (by hand) into JSON gives {
"name": "John Smith",
"address": { "streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": ["212 555-1111", "212 555-2222"],
"additionalInfo": null,
"remote": false,
"height": 62.4,
"ficoScore": " > 640"
}I expect many people were doing this by hand since JSON has replaced XML in a lot of peoples minds, and IBM has created a way to standardize it to make it easier to work with other teams.
If you don't want it to be readable, make the darn thing binary and go for efficiency.
On the plus side I bet the output gzip's up rather nicely in transit assuming you're HTTP GET'ting this data....
<object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.ibm.com/xmlns/prod/2009/jsonx">
<string name="name">John Smith</string>
<object name="address">
<string name="streetAddress">21 2nd Street</string>
<string name="city">New York</string>
<string name="state">NY</string>
<number name="postalCode">10021</number>
</object>
<array name="phoneNumbers">
<string>212 555-1111</string>
<string>212 555-2222</string>
</array>
<null name="additionalInfo" />
<boolean name="remote">false</boolean>
<number name="height">62.4</number>
<string name="ficoScore"> > 640</string>
</object>The XML is 901 bytes, gzip yields 401 (44.5%)
Of course the original JSON is 303 bytes and JSON is already pretty compressible, to 215 bytes (71%) in this case.
Because of what I just mentioned. If they had set the root namespace directly you wouldn't have to declare the namespace prefix on every element.
> The ampersand character (&) and the left angle bracket (<) must not appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they must be escaped using either numeric character references or the strings " & " and " < " respectively. The right angle bracket (>) may be represented using the string " > ", and must, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.
The output syntax is even more glorious than you'd think:
<?xml version="1.0" encoding="UTF-8"?> <json:object xsi:schemaLocation="http://www.datapower.com/schemas/json jsonx.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:json="http://www.ibm.com/xmlns/prod/2009/jsonx"> <json:string name="name">John Smith</json:string> <json:object name="address"> <json:string name="streetAddress">21 2nd Street</json:string> <json:string name="city">New York</json:string> <json:string name="state">NY</json:string> <json:number name="postalCode">10021</json:number> </json:object> <json:array name="phoneNumbers"> <json:string>212 555-1111</json:string> <json:string>212 555-2222</json:string> </json:array> <json:null name="additionalInfo" /> <json:boolean name="remote">false</json:boolean> <json:number name="height">62.4</json:number> <json:string name="ficoScore"> > 640</json:string> </json:object>
...and no, I'm not joking, and don't call me Shirley.