Json issue

Hi,

I have the following json obtained from an HTML form:

{"Requester":"SuperUser","Attachments":{"1":{"file":"D:\\temp\\myfile.txt","Services":"Serv1, Serv2","Organisation":"org1","Name":"myName","action":"create"}}}

Upon using Deserialize JSON activity, I get the error below, starting yesterday… I really can’t figure it out what changed that my input is not accepted anymore

Deserialize JSON: Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type ‘Newtonsoft.Json.Linq.JToken’ because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path ‘Attachments.1’, line 1, position 44.

that’s a nested json, you’ll have to use deserialize json array to get individual json element, and then deserialize json twice.

Below link will help

Hi.
I checked your example and it’s works fine.
I don’t know how you read this json but if it is a file you can use activity - “read text file” and after that deserialized.

I you are using string variable you have to remember about double quotes like: “{”“Requester”“:”“SuperUser”“,”“Attachments”“:{”“1"”:{““file””:““D:\temp\myfile.txt””,““Services””:““Serv1, Serv2"”,”“Organisation”“:”“org1"”,““Name””:““myName””,““action””:““create””}}}"

This has worked before and just stopped working…

It’s weird. Did you try upgrade or downgrade activities packs - UiPath.WebAPI.Activities ?

I have done the same test as you on a new project on the same machine and it works… I do not understand how a project can break, but it seems I’m not the only one… I did not modify anything, but the project just broke…

Once upon a time, I had a situation that my xaml file was corrupted. But then I couldn’t open file and I had to rewrite all code.
Maybe you will try copy code to new xaml file ?

In my project: create a new xaml file in which I just deserialize → error
In a new project on the same machine: create a new xaml the same as above → works ok
I copy in the new project my files and dependencies → the xaml that worked before doesn’t work anymore…

Hmmm. it’s really weird.
So maybe is it a project.json file issue. Maybe could you try copy the new one to the old project and check the results ?
From some reason your currently project is corrupted and it’s hard to find solution for this situation.

Found the culprit in an updated library
Uipath.WebAPI.Activities was saying that the library is satisfied by the one with higher version.
Deleting Newtonsoft.Json 13.0.1 solved the issue. It seems something has changed in that version…

2021-10-26 23_39_12-mRemoteNG - confCons.xml - jump 27

3 Likes

Super that you found solution.
Good to know for the future.

Yeah… Though it’s not nice to work during vacation :frowning:

1 Like

That’s good to know you found the issue and eliminated.

One thing I would like to mention here, if anything weird happens,ike in this case, i prefer to check the version of my packages and then click it remove unused dependencies. That helps to get out they used problem causing activities, as well as corresponding namespaces that are the real pain in case of conflicts

Happy Automating!