514
Views
1
Comments
Solved
JSON Deserialize Returns Blank
Question

Hi Team,

I am trying to De-serialize the JSON file attached. But the Output Structure returns null value for the geometry structure and for its Coordinates list. I created the Structure using Add structure from JSON the functionality provided by the platform, still the error persists. In the end user scenario, I uploaded the file using Upload widget and used Binary data to text function for Converting the binary data to text then passed the text data to JSON De-serialize and provided the data type structure created by Outsystems platform.

Please Advice! Thanks in Advance

FormatedJSON.txt
2021-03-18 21-03-15
Benjith Sam
 
MVP
Solution

Hi Saravanan,

I had tried to De-serialize the shared JSON file but got encountered with the below mentioned error even though the referred JSON string is valid.

Error Description

Failed to deserialize JSON to FeatureCollection:
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ssReactiveTestApp_UI.RestRecords.JSONSTCoordinateItemStructure' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path 'features[0].geometry.coordinates[0]', line 10, position 16.


Observation:

-  I guess the nested-array valued JSON string de-serialization is not possible in OutSystems platform 

Refer this https://www.outsystems.com/forums/discussion/44871/json-deserialization-against-a-json-which-has-nested-array-property/

""coordinates"":[
	[
	  -7.2399166829999331,
	  5.2881735040000422,
	  131.83999999999651
	],
	[
	  -7.2401958139999465,
	  5.2882043740000313,
	  132.24000000000524
	]
]


- The best possible way to solve such case is to convert the nested array to array of Objects as mentioned below, which will also help you to easily identify the attributes with the respective value (Key Value pairs)

I tried with the below edit and it works perfectly :)

"coordinates":[
    {
      "X":-7.2399166829999331,
      "Y":5.2881735040000422,
      "Z":131.83999999999651
    },
    {
      "X":-7.2405247009999698,
      "Y":5.287848231000055,
      "Z":156.76429999999527
    }
]

Hope this helps you!


Regards,

Benjith Sam

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