1816
Views
8
Comments
Solved
JSON Deserialize error
Question

Hi,


I have the following JSON String that needs to be deserialized:


{"localusers":
               {"mobile_number": ["Invalid mobile number"]
                , "password": ["Password must have at least 8 character(s)"]
               }
}


I created a structure like this:



The Value under JSONFortiAuthenticatorRec is of data type Text Record list


And the JSONFortiAuthenticatorRecList is of data type 


And the data type of the built in JSONDeserialize is of data type JSONResponseFortiAuthenticator Record list.

When I run it I get the error 

Failed to deserialize JSON to JSONResponseFortiAuthenticatorRecordList: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'ssReporterB.RestRecords.JSONRCJSONResponseFortiAuthenticatorRecord[]' 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 'localusers', line 1, position 14.



What am I doing wrong?


any help would be much appreciated.


Alexei



2016-04-21 20-09-55
J.
 
MVP
Solution

Hi Alexei,


Why did you create the structure manually?

You should right-click on the structure folder


Then past your json in the popup-window, name the structure and you are good to go

Then you know you (de)serialize will work.

2016-07-15 19-11-34
Alexei

J thanks for your quick reply.


The structure provided above is a returned result of a scenario I'm testing.

So I did indeed what you stated.


and it generated the following:



I provided the JSONDeserialize  with the structure1 as a record list




And I got the same result,


Failed to deserialize JSON to Structure1RecordList: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'ssReporterB.RestRecords.JSONRCStructure1Record[]' 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 'localusers', line 1, position 14.





2016-04-21 20-09-55
J.
 
MVP

Hi,


your json isn't a recordlist, simply have the datatype set to Structure1


2016-07-15 19-11-34
Alexei

J  many thanks for your help.


It works for the scenario above, but the structure is a dynamic structure based on what produces an error it will provide them in an array, like 


{"localusers":
               {"mobile_number": ["Invalid mobile number"]
                , "password": ["Password must have at least 8 character(s)"]

                , "First name": ["First Name is mandatory"]

                , ..........

                  .........
               }
}


so I cannot have them static as the structure is being created like the one below



I tried to make the structure like this:

( the LocalUser I have renamaed it to Topic)



but It will store only the information of the mobile number, but it will not append the information of the password to the list.

Do you know how I can accomplish this?


Alexei

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Alexei,

OutSystems doesn't support what you want. The JSON attribute name must be an Attribute name in an OutSystems structure. If that's the JSON you get, you need to parse it manually.

2016-07-15 19-11-34
Alexei

Kilian Hekhuis wrote:

Hi Alexei,

OutSystems doesn't support what you want. The JSON attribute name must be an Attribute name in an OutSystems structure. If that's the JSON you get, you need to parse it manually.


Kilian thanks for your reply, to bad that we cannot use dynamic list structures. 


2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Yes, it would be nice for these kind of use cases (I've seen them before), but as it is, like I said, you'll need to parse it yourself, unfortunately.

2016-04-21 20-09-55
J.
 
MVP

You can always create an idea (or look for a similar idea and upvote it :) )

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