Linx Main Linx Help

JSON Parsing Help

Hi, team

I downloaded the JSONExample solution by Dawie and understand the concept, but cannot get it to work with the JSON response returned by a REST API (which I have confirmed is a valid properly formed response). I tried to upload it here but it says new members cannot upload files, so I posted it to pastebin: JSON Response

Can someone please assist with a solution file as I have been trying all night to get it to work in Linx without any luck. :confused:

Hi Stoavio,

Thank you for your messages. In terms this JSON string. There is a “secret” which I always show people, but it’s so good that it should be a secret :slight_smile: .

Once you’ve successfully received a JSON response with a relatively complete structure, then copy that JSON into memory, go to your Linx Solution and right click on your project (or a folder). Selected “Import Custom Type” and paste the JSON into the textbox. Press “Create”.

Now Linx will create a “CustomType” based on the JSON you’ve provided, and you can use that as the return type of your JSONReader.

Very important note!
You need to understand your root JSON structure. If the JSON starts with a { - bracket, it means that the base / root object is a single object, and you can use it straight as a type for the JSON reader. However, as in your example, if the JSON starts with a [ - bracket, it means the root is a List or Array of your JSON objects. You need to then select List as your type and then select the JSON type you’ve imported.

I’ve attached the example of how I read your JSON:
ReadingStoavioJSON.lsoz (15.4 KB)


1 Like

Thank you, Dawie. That’s a pretty cool tip… I’ll give it a shot and let you know how it goes!