How to handle array of values for a field in REST API resp?

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
bondicoffee
Posts: 130
Joined: Tue Dec 03, 2013 10:19 pm

How to handle array of values for a field in REST API resp?

Post by bondicoffee »

Following is the response recieved from a REST service in JSON Format.
{
"data": [
{
"fieldname" : ["value1","value2"]
}
]
}
Following is my implementation for the above response :

1) Created BO_child with an attribute called "fieldname" of type Plain text.
2) Created BO_parent with "data" as its attribute of type BO_child

Records are getting created with null values.

How do I fix this issue?
Last edited by bondicoffee on Wed Dec 11, 2019 6:57 pm, edited 1 time in total.
swiftinitpvtltd
Posts: 370
Joined: Sat Apr 28, 2018 3:33 am
Location: India
Contact:

Re: How to handle array of values for a field in REST API re

Post by swiftinitpvtltd »

Not sure why you are getting null because if its plain text it should dump json formatted data in plain text(may be length is small try 1000 in your column). Quickly looking at this if you want to get some data out of it in useful format there may be aware way to get it and if its too complex then you will have to parse the json using jquery or js I think.
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: How to handle array of values for a field in REST API re

Post by BobK »

Your JSON is missing the last "}", or is that just a typo in your post.

What version of of AwareIM are you using?

I got this working (sort of) using build 2711.
I say sort of because only 1 BO_Child was created and the fieldname was populated with
value1^value2

I do not guarantee that I did not do something wrong myself, but I don't think that is what you want.

My guess is that AwareIM can not handle arrays in the format of
["value1","value2"]


I am no JSON expert, but I have only seen arrays like the following (which creates 2 BO_Child objects as expected)
{
"data": [
{
"fieldname": "value1"
},
{
"fieldname": "value2"
}
]
}
Bob
bondicoffee
Posts: 130
Joined: Tue Dec 03, 2013 10:19 pm

Re: How to handle array of values for a field in REST API re

Post by bondicoffee »

Thank you Bob for looking into the response sample closely and pointing to missed '}'.

With regard to your question on the AwareIm version, I am using v8.4 Build 2709. I will try updating Awareim and verify if this works. Thanks :)

Is there a way in Awareim to collect whole JSON data in one attribute? I plan to update this JSON response using string manipulations and then create BO.
BobK
Posts: 544
Joined: Thu Jan 31, 2008 2:14 pm
Location: Cincinnati, Ohio, USA

Re: How to handle array of values for a field in REST API re

Post by BobK »

bondicoffee wrote:Is there a way in Awareim to collect whole JSON data in one attribute? I plan to update this JSON response using string manipulations and then create BO.
Yes.

On your intelligent BO, where you set the REST settings.
in the Reply section, check "Reply returned" and click on "Details..."
select "Write into object in Context" and select your desired BO from the Object drop down
and from the Attribute drop down, select the BO's attribute to write the data into.
Bob
bondicoffee
Posts: 130
Joined: Tue Dec 03, 2013 10:19 pm

Re: How to handle array of values for a field in REST API re

Post by bondicoffee »

Thanks Bob! Appreciate your quick response!
aware_support
Posts: 7523
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: How to handle array of values for a field in REST API re

Post by aware_support »

Code: Select all

My guess is that AwareIM can not handle arrays in the format of
["value1","value2"]
It can. It is mapped to a single string with the ^ symbol as a delimiter between array members.

Object.Attribute = "value1^value2"

But it shouldn't be null
Aware IM Support Team
Post Reply