Both the XML and JSON output from Dream services contain the same data; the only difference is in the format. The documentation on OpenGarden assumes XML output. In general you can assume these rules:
By default all data exchanges with Dream services use XML. However, an XML response can be automatically converted to JSON by using the dream.out.format=jsonp parameter in the request URI:
http://dreamserver/stats/record/RESPONSE_TIME&dream.out.format=jsonp
In addition to the dream.out.format parameter, the URI can also contain a dream.out.pre parameter to prefix the JSON output with a function invocation. For example:
http://dreamserver/stats/record/RESPONSE_TIME&output=json&dream.out.pre=show_stats This request results in the following output:
show_stats( ...json output... );
Because JSON output is already JavaScript, it is automatically evaluated as a JavaScript object and you can access the elements inside it as if you had passed an object reference to your show_stats function.
The name of the callback function must be valid JavaScript identifier and thus can only contain upper and lowercase alphabetic characters (A-Z a-z), numbers (0-9), and underscore (_).
<stat> <name>stat1</name> <source>http://localhost:8081/stats/record/stat1/</source> <service>http://localhost:8081/stats/</service> <min>0</min> <max>9.594</max> <avg>4.914</avg> <var>0.14535147392290246</var> <sum>49.14</sum> <count>10</count> <first>2006-05-17T00:26:36.6098976-07:00</first> <last>2006-05-17T00:42:27.4853392-07:00</last> <rate>95.08754416</rate> <ratevar>0.99909449928635941</ratevar> </stat>
({
"stat" : {
"name" : "stat1",
"source" : "http://localhost:8081/stats/record/stat1/",
"service" : "http://localhost:8081/stats/",
"min" : "0",
"max" : "9.594",
"average" : "4.914",
"variance" : "0.14535147392290246",
"sum" : "49.14",
"count" : "10",
"first" : "2006-05-17T00:26:36.6098976-07:00",
"last" : "2006-05-17T00:42:27.4853392-07:00",
"rate" : "95.08754416",
"ratevar" : "0.99909449928635941"
}
}) ws_show_stats({
"stat" : {
"name" : "stat1",
"source" : "http://localhost:8081/stats/record/stat1/",
"service" : "http://localhost:8081/stats/",
"min" : "0",
"max" : "9.594",
"average" : "4.914",
"variance" : "0.14535147392290246",
"sum" : "49.14",
"count" : "10",
"first" : "2006-05-17T00:26:36.6098976-07:00",
"last" : "2006-05-17T00:42:27.4853392-07:00",
"rate" : "95.08754416",
"ratevar" : "0.99909449928635941"
}
}) The JSON format can be output in two variations: with and without surrounding parenthesises. Since parenthesises have no impact on evaluation, they don't hurt when the desired output is only a JSON expression. However, when requiring a function call prefix, "jsonp" only requires the extra noun, whereas "json" needs the noun and the opening parenthesis in URL encoded format, plus a postfix closing the parenthesis.
The following two calls are equivalent:
GET http://dreamserver/stats/record/stat...=ws_show_stats
GET http://dreamserver/stats/recrod/stat...eam.out.post=)
Because "jsonp" is simpler to use and less error prone, it is generally preferred over the "json" output format, which remains supported for backwards compatibility.