cancel
Showing results for 
Search instead for 
Did you mean: 

Utility-JSON issue

PranavNayak
Level 3
Hi, While working with the VBO 'Utility-JSON', I used both the actions(viz. JSON to Collection,Collection to JSON) given in the VBO and found that if the input is a json containing some field as an array,and if I use both theses actions one after the other ie(using JSON to collection first and then using Collection to Json to the sample collection) the output JSON message doesn't match the input JSON message.The array fields get wrapped in another array.Also the entire JSON object gets wrapped as an array. Any solution to solve this issue?
11 REPLIES 11

Denis__Dennehy
Level 15
I recommend that you see the JSON utility we provide as a starting point example - it works very well with simple web services (I have used it several times myself) but if your web service requires a non-standard or embeded structure than you may have to take the code Blue Prism provides and expand it into something that works for you.

I'm facing the same issue currently - is there really no other way than programming the (de)serialization ​myself?

------------------------------
Cheers Astrid
------------------------------
Cheers [FirstName]

Can you provide an example JSON Astrid? If a bespoke code solution is your best option, I've found using the ExpandoObject relatively painless:

Dim objJSON As Object = JsonConvert.DeserializeObject(Of ExpandoObject)(strJSON)
For Each thing As Object In objJSON.Level1.Level2.things
   'Do stuff here
Next

------------------------------
John Carter
Professional Services
Blue Prism
------------------------------

Hi John,

 

many thanks for your reply.

 

While trying to prepare an example,  I noticed that the "JSON to Collection (skipping JArray)" action seems to resolve this issue.  

The only "problem" is now, that the "Collection to JSON" function adds a set of square brackets around the JSON string which the REST service I'm calling doesn't like. So I need to remove them using a calculation stage. But the rest seems to work fine then.

 

Thx,

Astrid



------Original Message------

Can you provide an example JSON Astrid? If a bespoke code solution is your best option, I've found using the ExpandoObject relatively painless:

Dim objJSON As Object = JsonConvert.DeserializeObject(Of ExpandoObject)(strJSON)
For Each thing As Object In objJSON.Level1.Level2.things
   'Do stuff here
Next

------------------------------
John Carter
Professional Services
Blue Prism
------------------------------
Cheers [FirstName]

Hi John,

I was able to reproduce the issue now: 

1. I'm using "JSON to Collection (skipping JArray)" with following JSON as Input and store the output in a collection "Coll":
{"filterCriterias":[{"attribute":"originator","filterType":"EQUALS","value":"1234567"}],"sortCriteria":{"sortType" : "DESC","sortBy": "id"}}

This returns a Collection containing 2 Collections, 1 row each.

2. Then I'm using "Collection to JSON" with the collection "Coll" as Input which returns:
[{"filterCriterias":[{"attribute":"originator","filterType":"EQUALS","value":"1234567"}],"sortCriteria":[{"sortType":"DESC","sortBy":"id"}]}]

So there are a few more square brackets in the resulting JSON string which my REST service doesn't accept. 

I'd like to build a generic "search" action where users can pass the search criteria in one collection as input parameter.
I'd then transform this Collection to a JSON and use this for the REST service call, but as described above, the "Collection to JSON" doesn't return a JSON which my REST service accepts...

Any ideas?

------------------------------
Cheers Astrid
------------------------------
Cheers [FirstName]

​Hi Astrid,

a while ago I re-worked the complete Json Library. Maybe you can give it a try. see here: Using JSON VBO


------------------------------
Tobias Arnold
RPA Developer
ITERGO GmbH
Europe/Duesseldorf
------------------------------

Hi Tobias.

many thanks for your reply.

I actually found out that making my Input Collection a "Single Row" collection solves my problem with the surrounding square brackets which my REST service doesn't like.

I still tried your object quickly but it didn't convert the collection in the collection correctly. Instead of the parameter name it gave me "JSONArray"...

Thanks anyway!

------------------------------
Cheers Astrid
------------------------------
Cheers [FirstName]

Hi Astrid! I went through the same problem, and with me team we could develop this solution in a Calculation

Replace(Replace(Left(Right([Json Body], Len([Json Body])-1), Len([Json Body])-2), "[[{", "[{"), "}]]", "}]")

I hope it works!

Best wishes!
Federico

------------------------------
Federico Mignone
------------------------------

Thanks, Federico!

I don't remember anymore actually how I solved it in the end, but I think it involved defining the result collection as "single row" (which requires to define the fields as well of course, so it's not super generic anymore but it worked for my process...).


------------------------------
Cheers Astrid
------------------------------
Cheers [FirstName]