Author |
Message
|
ChecoTirado |
Posted: Mon Feb 01, 2016 1:38 pm Post subject: Collection+JSON PUT WebService |
|
|
Newbie
Joined: 01 Feb 2016 Posts: 6
|
hi Everyone, I need your help.
I'm building a REST Webservice with the PUT tag but I don't know how to read the next structure as INPUT:
{ "template" : {
"data" : [
{"name" : “periodo”, "value" : “201313”},
{"name" : “folio”, "value" : “5”},
{"name" : “cumple”, "value" : “SS”},
{"name" : “usuario”, "value" : “WS”}
]
}
}
I'm trying with InputRoot object, but I don't know how.
SET cTemp = InputRoot.JSON.Data.template.data.item[1].name.value;
Please advise.
Checo. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Feb 01, 2016 1:43 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Once a message has been parsed by IIB, then you do not care whether it's REST or JSON or XMLNSC or DFDL or etc. etc. etc.
You treat it as a logical message tree.
Any of the samples that come with the product will show you how to navigate the logical message tree.
This is basic IIB programming. You should read the docs, study the samples, and try them. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
ChecoTirado |
Posted: Mon Feb 01, 2016 1:52 pm Post subject: |
|
|
Newbie
Joined: 01 Feb 2016 Posts: 6
|
I tryed with the examples but I didn't found with this type of structure. Would you like to guide me how to read these kind of structure?
Please |
|
Back to top |
|
 |
ChecoTirado |
Posted: Mon Feb 01, 2016 2:13 pm Post subject: |
|
|
Newbie
Joined: 01 Feb 2016 Posts: 6
|
I got these error
"code": 5701,
"message": "5701: A JSON parsing error has occurred whilst parsing the JSON document \"[\", \"{\", \"value\"" |
|
Back to top |
|
 |
sumit |
Posted: Mon Feb 01, 2016 2:57 pm Post subject: |
|
|
Partisan
Joined: 19 Jan 2006 Posts: 398
|
ChecoTirado wrote: |
{ "template" : {
"data" : [
{"name" : “periodo”, "value" : “201313”},
{"name" : “folio”, "value" : “5”},
{"name" : “cumple”, "value" : “SS”},
{"name" : “usuario”, "value" : “WS”}
]
}
}
.....
I got these error
"code": 5701,
"message": "5701: A JSON parsing error has occurred whilst parsing the JSON document \"[\", \"{\", \"value\"" |
Any JSON message that you want IIB to parse should be a valid JSON message.
Please refer this link to understand how to work with a JSON message in IIB.
https://www-01.ibm.com/support/knowledgecenter/SSMKHH_9.0.0/com.ibm.etools.mft.doc/bc28410_.htm?lang=en _________________ Regards
Sumit |
|
Back to top |
|
 |
sumit |
Posted: Mon Feb 01, 2016 3:02 pm Post subject: |
|
|
Partisan
Joined: 19 Jan 2006 Posts: 398
|
hint: there are few invalid JSON characters in your sample JSON message. Rectify and validate it first. _________________ Regards
Sumit |
|
Back to top |
|
 |
ChecoTirado |
Posted: Mon Feb 01, 2016 3:13 pm Post subject: |
|
|
Newbie
Joined: 01 Feb 2016 Posts: 6
|
I read the example you sent, but I dont understand is how to use the InputRoot object to parse this specific structure.
This structure is Collection+JSON. http://amundsen.com/media-types/collection/
Ive been able to use the OutputRoot object to return this structure but I dont know how to receive it as input.
I checked the JSON
{ "template" : {
"data" : [
{"name" : "periodo", "value" : "201313"},
{"name" : "folio", "value" : "5"},
{"name" : "cumple", "value" : "SS"},
{"name" : "usuario”, "value" : "WS"}
]
}
}
I'm using this line: SET cTemp = InputRoot.JSON.Data.template.data.item[1].data.item[1].name;
to get "periodo" into the cTemp variable.
Whats wrong?
Please advise |
|
Back to top |
|
 |
Simbu |
Posted: Mon Feb 01, 2016 9:50 pm Post subject: |
|
|
 Master
Joined: 17 Jun 2011 Posts: 289 Location: Tamil Nadu, India
|
Hi, use http://jsonlint.com/ copy & paste your json message, validate it and fix the error with the json. Next, Please test and check the logical tree structure of your json message in the debug to ensure that your json is parsed successfully. |
|
Back to top |
|
 |
stoney |
Posted: Mon Feb 01, 2016 9:58 pm Post subject: |
|
|
Centurion
Joined: 03 Apr 2013 Posts: 140
|
Quote: |
{ "template" : {
"data" : [
{"name" : "periodo", "value" : "201313"},
{"name" : "folio", "value" : "5"},
{"name" : "cumple", "value" : "SS"},
{"name" : "usuario”, "value" : "WS"}
]
}
}
I'm using this line: SET cTemp = InputRoot.JSON.Data.template.data.item[1].data.item[1].name; |
You have too many arrays in the ESQL; there's only one in the JSON you've posted. You've also got a lowercase 'i' in your Item. Should be:
SET cName = InputRoot.JSON.Data.template.data.Item[1].name
Quote: |
SET cTemp = InputRoot.JSON.Data.template.data.item[1].name.value; |
You need to read name and value as two separate elements:
SET cName = InputRoot.JSON.Data.template.data.Item[1].name;
SET cValue = InputRoot.JSON.Data.template.data.Item[1].value; |
|
Back to top |
|
 |
ChecoTirado |
Posted: Mon Feb 01, 2016 9:59 pm Post subject: |
|
|
Newbie
Joined: 01 Feb 2016 Posts: 6
|
Done, this site says the JSON is valid. |
|
Back to top |
|
 |
ChecoTirado |
Posted: Mon Feb 01, 2016 10:15 pm Post subject: |
|
|
Newbie
Joined: 01 Feb 2016 Posts: 6
|
stoney wrote: |
Quote: |
{ "template" : {
"data" : [
{"name" : "periodo", "value" : "201313"},
{"name" : "folio", "value" : "5"},
{"name" : "cumple", "value" : "SS"},
{"name" : "usuario”, "value" : "WS"}
]
}
}
I'm using this line: SET cTemp = InputRoot.JSON.Data.template.data.item[1].data.item[1].name; |
You have too many arrays in the ESQL; there's only one in the JSON you've posted. You've also got a lowercase 'i' in your Item. Should be:
SET cName = InputRoot.JSON.Data.template.data.Item[1].name
Quote: |
SET cTemp = InputRoot.JSON.Data.template.data.item[1].name.value; |
You need to read name and value as two separate elements:
SET cName = InputRoot.JSON.Data.template.data.Item[1].name;
SET cValue = InputRoot.JSON.Data.template.data.Item[1].value; |
Thank Stoney, This works perfectly. |
|
Back to top |
|
 |
|