|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
JSON domain adds "Item" to each array |
« View previous topic :: View next topic » |
Author |
Message
|
noreen.abdallah |
Posted: Mon Sep 11, 2023 3:44 am Post subject: JSON domain adds "Item" to each array |
|
|
Newbie
Joined: 11 Sep 2023 Posts: 2
|
Dears,
I am calling rest API which and at a part of the project I want to return the response of that API as-is, but the problem is that the output contains "Item" before each array, and it's required to be removed to be just as the input.
I have tried to get it as BLOB and turn it into character and then put it as a value of json object but then it adds a \" to each " which makes sense but it doesn't solve the problem. |
|
Back to top |
|
 |
mgk |
Posted: Mon Sep 11, 2023 4:23 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi.
I would not expect that the "item" name before each element in an array is serialised as part of the output message and a quick test shows me that it is not. Item is present inside the logical message tree (inside the flow) to allow easier access but should not present in the output
Can you post an example of your input message and the output message with the problem please?
Kind regards. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
noreen.abdallah |
Posted: Mon Sep 11, 2023 9:44 am Post subject: |
|
|
Newbie
Joined: 11 Sep 2023 Posts: 2
|
Here is a sample input
Code: |
"sample_input": {
"0": [
{
"A": "AValue"
},
[
{
"B": "BValue"
},
[
{
"B": "BValue"
},
{
"B": "BValue"
}
],
[
{
"B": "BValue"
},
{
"B": "BValue"
}
]
],
[
{
"B": "BValue"
},
[
{
"B": "BValue"
},
{
"B": "BValue"
}
],
[
{
"B": "BValue"
},
{
"B": "BValue"
}
]
],
{
"A": "AValue"
}
]
}
|
Here is when I use:
Code: |
SET Environment.Variables.fullResponse = InputRoot.JSON.Data;
SET OutputRoot.JSON.Data.fullResponse = Environment.Variables.fullResponse;
|
sample output:
Code: |
"sampleOutput": {
"0": {
"Item": {
"Item": {
"A": "AValue"
},
"Item": {
"Item": {
"Item": {
"B": "BValue"
},
"Item": {
"Item": {
"Item": {
"B": "BValue"
},
"Item": {
"B": "BValue"
}
}
},
"Item": {
"Item": {
"Item": {
"B": "BValue"
},
"Item": {
"B": "BValue"
}
}
}
}
},
"Item": {
"Item": {
"Item": {
"B": "BValue"
},
"Item": {
"Item": {
"Item": {
"B": "BValue"
},
"Item": {
"B": "BValue"
}
}
},
"Item": {
"Item": {
"Item": {
"B": "BValue"
},
"Item": {
"B": "BValue"
}
}
}
}
},
"Item": {
"A": "AValue"
}
}
}
}
|
And here is a sample output when I use:
SET OutputRoot.JSON.Data.fullResponse =InputRoot.JSON.Data;
Code: |
"sampleOutput": {
"0": {
"Item": [
{
"A": "AValue"
},
{
"Item": [
{
"B": "BValue"
},
{
"Item": [
{
"B": "BValue"
},
{
"B": "BValue"
}
]
},
{
"Item": [
{
"B": "BValue"
},
{
"B": "BValue"
}
]
}
]
},
{
"Item": [
{
"B": "BValue"
},
{
"Item": [
{
"B": "BValue"
},
{
"B": "BValue"
}
]
},
{
"Item": [
{
"B": "BValue"
},
{
"B": "BValue"
}
]
}
]
},
{
"A": "AValue"
}
]
}
}
|
 |
|
Back to top |
|
 |
mgk |
Posted: Tue Sep 12, 2023 2:06 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
In your first example you run:
Code: |
SET Environment.Variables.fullResponse = InputRoot.JSON.Data;
SET OutputRoot.JSON.Data.fullResponse = Environment.Variables.fullResponse; |
And this forces an "unlike parser copy" as the Environment tree does not create a JSON parser for you automatically, and it is this that "forces" the "Item" elements to be kept as the "unlike parser copy" loses the special json array type on the array elements as part of the copy. To make this work you would need to create a parser under the target like this:
Code: |
CREATE LASTCHILD OF Environment.Variables DOMAIN 'JSON' NAME 'fullResponse';
SET Environment.Variables.fullResponse = InputRoot.JSON.Data;
SET OutputRoot.JSON.Data.fullResponse = Environment.Variables.fullResponse; |
When I tested the above in a simple "HTTP Input" -> "ESQL Compute" -> "HTTP Reply" flow with your input message this worked as expected and the "Item" elements did not appear in the output message.
In your second example, you said you ran:
Code: |
SET OutputRoot.JSON.Data.fullResponse =InputRoot.JSON.Data; |
This gives you a "like parser copy" and I would expect this to work. And when I tested in with your input message I do not see the "Item" elements in the output message as expected as so it is working for me. So my guess is that your deploy did not complete properly for some other reason and if you retry and make sure it is deployed it should work.
For more information about "like" and "unlike" parser copies see: https://www.ibm.com/docs/en/app-connect/12.0?topic=another-changing-message-format
I hope this helps. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
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
|
|
|
|