Parsing unexpected JSON responses

Fields with full stops

A rare case recently arose whereby field names in a JSON response had a “break” in them in the form of a full stop (“.”) like the below:

{
   "Ordering_Form":[
      {
         "Order_ID":334223,
         "Order_Status":"Prepared",
         "Customer_Name.Delivery_Address":"Linx Software, Cape Town",
         "Production_Date_Main":"2020-11-10 17:00:00",
         "Total_Amount":"R 780.00",
         "Customer_Name":"Linx Software",
         "Customer_Name.Customer_Area_Code":"7945",
         "Customer_Name.Email":"support@linx.software",
         "ID":4029474000000032031
      }
   ]
}

In the above example, an Ordering_Form contains a number of fields with order related information, some of these fields contain a “.” like in the case of Customer_Name.Email.

If you import the above as a TypeTYP, the invalid characters in the field name will be replaced like below:

{
   "Order_ID":0,
   "Order_Status":"",
   "Customer_Name_46Delivery_Address":"",
   "Production_Date_Main":"",
   "Total_Amount":"",
   "Customer_Name":"",
   "Customer_Name_46Customer_Area_Code":"",
   "Customer_Name_46Email":"",
   "ID":0
}
Note: When importing a TypeTYP, field names containing invalid characters will be converted according to these conventions.

However, if you try to assign data object above to the imported TypeTYP, the field’s containing names with “.” are not assigned and no error is thrown:

image

To resolve this issue, you need to map the fields to a CustomTypeTYP by using a JSONReaderFNC .

The JSONReaderFNC has the below Properties:

  • Json string: Input data string to serialize.
  • Output type: The CustomTypeTYP to serialize the data into.
  • Property map: This is used to manually map the JSON fields from the Json string onto the fields of the Output type.

Mapping Fields

To manually map fields from the Json string onto the fields of the Output type, expand the Property map property to open the field editor.

The editor has two columns:

  • JSON Name: The is the name of the field as it originally appears in the Json string.
  • Property Name: This is the name of the corresponding field of the Output type.

This allows you to manually control which fields get assigned to which, as well as solve the issue of the “.” in the field names.

In order to resolve the issue, add the names of the fields like they appear in the original string, and then map them to the Output type fields like below:

image

The result of the JSONReaderFNC will be the correctly parsed fields like the below:

image

Sample:

Linx5 - Solution.lsoz (5.7 KB)
Linx6 - Linx6.zip (3.4 KB)