Issue while using Deserialize activity

Hello,

I have an issue while trying to use “deserialise”. I use an HTTP request that give me the following string :

{“header”:{“statut”:200,“message”:“ok”},“etablissement”:{“adresseEtablissement”:{“numeroVoieEtablissement”:“5”,“indiceRepetitionEtablissement”:null,“typeVoieEtablissement”:“RUE”,“libelleVoieEtablissement”:“LAVOISIER”,“codePostalEtablissement”:“59130”,“libelleCommuneEtablissement”:“LAMBERSART”}}}

My need is : to get the object/value starting “numeroVoieEtablissement” up to “libelleCommuneEtablissement” in arguments.

The api was updated and it doesn’t work anymore. (it went from ’ to " )

I used to :
Deserialize once, to get a Jobject variable
Then : Deserialize variable(“etablissement”).ToString -> to a Jobject variable
Then : Deserialize a third time : variable(“adresseEtablissement”).ToString.

Can anyone help me on how to get the values ?

Thanks a lot

7 Likes

What is the error you are receiving? Have you been able to verify the JSON format?

2 Likes

Hello, :

Here is the error I get : 19.4.3+Branch.support/v2019.4.Sha.a8f4efb75012dc834aa4be501a7086e9372ef1b3

Source: Deserialize JSON

Message: 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 ‘header.statut’, line 1, position 20.

Exception Type: Newtonsoft.Json.JsonSerializationException

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
Newtonsoft.Json.JsonSerializationException: 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 ‘header.statut’, line 1, position 20.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at UiPath.Web.Activities.DeserializeJson`1.Execute(CodeActivityContext context)
at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

I tried using a deserialize array, but it doesn’t work either

Thanks for your reply. :slight_smile:

4 Likes

Still looking for my MVP
@Martin_CHAUDEY ?

4 Likes

The activity Deserialize JSON will work fine for your response…

1 Like

Hello @bcorrea,

That is where my issue comes from, if you try the string I put earlier, you will find that you can not deserialize it as it is.
I can not comprehend why.

4 Likes

@VDEBAC

Hi , yes it will not work because it does’t like Json & as well as Json Array I don’t know why it is so,

I hope you tried JsonArray deserialise as well … put your string within [ your string ]

But you can get answer using Regex Pattern

Example

if your want to extract value numeroVoieEtablissemen

2 Likes

Thanks for your time,

My issue here is that the " are considered as opening and ending of strings and I can not work with it correctly.
I tried using double quote at the begining and the end, yet it didn’t work.
Maybe you have a tip ?

Thanks

5 Likes

@VDEBAC

May I know please, Why don’t we use Regex Pattern methodology to extract value …

1 Like

I can not make it work.
If I try to use the expression you gave me inside a “matches” activity it does not give me “5”

Do you know the correct expression I should use ?

Thanks

4 Likes

What do you mean? I copied and paste it here and it worked just fine…

1 Like

@VDEBAC

Test Value Should be your Https Request Ouput … Like this

{“header”:{“statut”:200,“message”:“ok”},“etablissement”:{“adresseEtablissement”:{“numeroVoieEtablissement”:“5”,“indiceRepetitionEtablissement”:null,“typeVoieEtablissement”:“RUE”,“libelleVoieEtablissement”:“LAVOISIER”,“codePostalEtablissement”:“59130”,“libelleCommuneEtablissement”:“LAMBERSART”}}}

1 Like

Hello @amaresan,

I found the issue, but can’t solve it : the quotation mark in my string are not standard :
they are “header” instead of " "

As a result the deserialize does not work. I tried using string.replace("“","""") but nothing works.

Can you help me ? how can I transform correctly the string ?

Thanks a lot.

Le lun. 14 oct. 2019 à 09:09, Amar via UiPath Community Forum uipath@discoursemail.com a écrit :

4 Likes

That is true, when i said it worked for me, i did convert all the quotation marks manually, but i thought it got formatted cause of the forum, do you actually get that response from your service call?

1 Like

Yes sadly :sob:

4 Likes

Well that would be the weirdest service response i ever seen, it does look like that response came from like some text editing software, like MS Word and got that formatted quotation marks…

1 Like

I had asked at the start of it had been verified as valid JSON format.

You can use online tools to do that:

As you can see, this returns it as invalid

1 Like

@VDEBAC

I think HTTP will not return like … I Don’t know how u will get this …

Anyway use below code to replace “header”. This Quotation

System.Text.Encoding.ASCII.GetString(System.Text.Encoding.ASCII.GetBytes(variable1)).Replace("?","""")

Variable1 is your HTTP Request Ouput which means this

{“header”:{“statut”:200,“message”:“ok”},“etablissement”:{“adresseEtablissement”:{“numeroVoieEtablissement”:“5”,“indiceRepetitionEtablissement”:null,“typeVoieEtablissement”:“RUE”,“libelleVoieEtablissement”:“LAVOISIER”,“codePostalEtablissement”:“59130”,“libelleCommuneEtablissement”:“LAMBERSART”}}}

Check and keep me informed

2 Likes

I think i know why your are getting this response, please check when you make the call if you are setting the header of Content-Type as “application/json”, then your response should arrive correctly.

1 Like

Hello,

It seems to be stuck on the caracter 20, meaning the : before 200
I don’t get it

4 Likes