|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
JSON Parsing Options |
« View previous topic :: View next topic » |
Author |
Message
|
jfrankman |
Posted: Mon Oct 26, 2009 12:24 pm Post subject: JSON Parsing Options |
|
|
Apprentice
Joined: 18 Jun 2009 Posts: 36
|
I have a requirement to call a REST service that returns data in the JSON format rather than XML. The response data I need to handle looks like:
Code: |
{
"directions" : [
{
"routeId" : 1,
"routeName" : "Route A",
"summary" : {
"totalLength" : 0.547668419055269,
"totalTime" : 0.916666666666667,
"totalDriveTime" : 0.9333050287275,
"envelope" : {
"xmin" : -122.408067,
"ymin" : 37.7820000000001,
"xmax" : -122.402715,
"ymax" : 37.785718,
"spatialReference" : {
"wkid" : 4326
}
}
},
"features" : [
{
"attributes" : {
"length" : 0,
"time" : 0,
"text" : "Start at From",
"ETA" : 1256576400000,
"maneuverType" : "esriDMTDepart"
},
"compressedGeometry" : "+1m91-6fki2+202vh+0+0"
},
{
"attributes" : {
"length" : 0.0250344870524692,
"time" : 0.0426480013199632,
"text" : "Go northwest on 5th St toward Cyril Magnin St/Market St",
"ETA" : 1256576400000,
"maneuverType" : "esriDMTStraight"
},
"compressedGeometry" : "+1m91-6fki2+202vh-h+f"
},
{
"attributes" : {
"length" : 0.168853162577195,
"time" : 0.287840826860452,
"text" : "Turn right on Market St",
"ETA" : 1256576403000,
"maneuverType" : "esriDMTTurnRight"
},
"compressedGeometry" : "+1m91-6fkij+20300+r+l+d+b+2h+1v"
},
{
"attributes" : {
"length" : 0.244708536869812,
"time" : 0.41608766827021,
"text" : "Turn right on 4th St",
"ETA" : 1256576420000,
"maneuverType" : "esriDMTTurnRight"
},
"compressedGeometry" : "+1m91-6fkeq+2032v+7-1+7-4+u-p+h-d+t-p+1-1+3-2+a-9+f-c+v-o+q-k"
},
{
"attributes" : {
"length" : 0.109072232555793,
"time" : 0.186728532276876,
"text" : "Turn right on Howard St",
"ETA" : 1256576445000,
"maneuverType" : "esriDMTTurnRight"
},
"compressedGeometry" : "+1m91-6fk9a+202un-o-j-1m-1b"
},
{
"attributes" : {
"length" : 0,
"time" : 0,
"text" : "Finish at To, on the left",
"ETA" : 1256576456000,
"maneuverType" : "esriDMTStop"
},
"compressedGeometry" : "+1m91-6fkbo+202sp+0+0"
}
]
}
],
"routes" : {
"features" : [
{
"attributes" : {
"ObjectID" : 1,
"Name" : "Route A",
"FirstStopID" : 1,
"LastStopID" : 2,
"StopCount" : 2,
"Total_Time" : 0.9333050287275,
"Shape_Length" : 0.00899201985728257
},
"geometry" :
{
"paths" :
[
[
[-122.407752312194, 37.7837382120084],
[-122.408067, 37.7839990000001],
[-122.407574, 37.7843920000001],
[-122.407333, 37.7845800000001],
[-122.407333001116, 37.7845799991291],
[-122.405883, 37.785718],
[-122.405085000068, 37.7851810000572],
[-122.405085, 37.785181],
[-122.404784, 37.784938],
[-122.404271, 37.7845010000001],
[-122.404239, 37.784477],
[-122.4042, 37.7844470000001],
[-122.404006, 37.784283],
[-122.403736, 37.7840659999999],
[-122.403184, 37.7836300000001],
[-122.402715, 37.7832650000001],
[-122.403146, 37.782924],
[-122.404116346791, 37.7821449081137]
]
]
}
}
]
},
"messages" : [
]
} |
I have already checked, and the service provider's SOAP service is not ready for prime time yet so I am left with the JSON format. I am wondering what options I have to be able to handle this.
1. Is there any third-party JSON nodes available?
2. Could regular expression syntax be used to extract data ?
3. Are there any other options for being able to process JSON response messages?
If anyone has had experience with this sort of thing or can point me in the right direction, I would appreciate it. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Oct 26, 2009 1:08 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
The problem with modelling JSON in Broker TDS is that JSON is recursively defined. That is, an Object can contain an instance of an Object.
You can get close by using wildcards.
Your best bet is to read the response as BLOB and pass it to a real JSON parser in a JavaCompute or PHPCompute node. |
|
Back to top |
|
 |
jfrankman |
Posted: Tue Oct 27, 2009 11:53 am Post subject: |
|
|
Apprentice
Joined: 18 Jun 2009 Posts: 36
|
I have retrieved the JSON response as a BLOB, but am a bit confused how to convert it to a char for processing. Will:
Code: |
Set jsonResponse =Cast(InputRoot.BLOB.BLOB as char); |
work? |
|
Back to top |
|
 |
kimbert |
Posted: Tue Oct 27, 2009 12:06 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
You *must* specify the encoding of the characters when converting from a BLOB to a character string. That's not a message broker restriction - the same would apply in any other language.
There are plenty of examples on this forum, so the search button is your friend. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|