Failed to deserialize JSON
Application Type
Traditional Web

I am new at OutSystems and I'm trying to deserialize the content which is an attribute from an entity.

However it ends in error:

Failed to deserialize JSON to Contract: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ssMyApp.RestRecords.JSONSTContractStructure' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.

How can I prevent this from happening?

MyApp.oml

mvp_badge
MVP
Solution

Hi Marco Silva,

Based on the shared use case, I guess you are trying to deserialize JSON string, an array of contracts.

Refer to this related post: Forum Post

I made some code changes in the shared .oml file. Please find the attachment (comments are also included for the code changes)


Code Changes:

  • Change the Data Type field value of the JSON Deserialize node to Contract Structure List type and use the ListAppendAll server action to append the list of deserialized contracts

I hope this helps you!


Kind regards,

Benjith Sam

MyAppupdated.oml

mvp_badge
MVP

Hello Marco,

The error is correct, the built-in JSON deserializer does not allow you to turn an array of simple types into an Object.

You have a couple of options:

  1. Change your code to give you a structure that OutSystems can parse (e.g. [{"value":1},{"value":2},{"value":3}]
  2. Use ardoJSON to query your JSON array instead of the built-in JSON capabilities
  3. Write an extension in C# to parse the JSON (though you will still have to convert it into a name value structure in the end)

@Craig St.Jean  I'm not sure if I can do these options:

I am trying to export the desiarelized content. 

On the OML I have the structure it was created by using the Add structure from JSON.

The option for the ardoJson I also don't understand. 

mvp_badge
MVP
Solution

Hi Marco Silva,

Based on the shared use case, I guess you are trying to deserialize JSON string, an array of contracts.

Refer to this related post: Forum Post

I made some code changes in the shared .oml file. Please find the attachment (comments are also included for the code changes)


Code Changes:

  • Change the Data Type field value of the JSON Deserialize node to Contract Structure List type and use the ListAppendAll server action to append the list of deserialized contracts

I hope this helps you!


Kind regards,

Benjith Sam

MyAppupdated.oml

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.