I have come across a challenging issue with a complex SLC loopback query and the JSON format it returns. Despite my best efforts to find a solution, I seem to be struggling to grasp some of the answers or perhaps I am approaching the problem from the wrong angle.
The JSON format returned by the API looks like this:
> [ {"id":"1","name":"John", "type":"commercial",
> "address":{"street1":"1 dalhousie lane", "street2":"some street"}},
> {"id":"2","name":"Jane", "type":"commercial",
> "address":{"street1":"15 dalhousie lane", "postcode":"1283833"}},
> {"id":"3","name":"Jack", "address":{"street1":"12 dalhousie lane",
> "postcode":"9383833", "geo":{"lat":"9393939","long":"99393939"}}}
Upon closer inspection, I have identified a couple of issues: 1. The JSON is nested with multiple levels. 2. There are inconsistencies and missing key values, such as missing "type" for "id":"2" and missing "geo" under "address" for "id":"3".
My attempt to display this JSON using the KendoUI grid resulted in errors like 'property undefined'. I understand the options available to me and what needs to be done:
- Define the schema: How can I handle missing keys?
- Parse the data?
I would greatly appreciate it if someone could guide me on how to proceed. Below is the code snippet for the grid:
$("#grid").kendoGrid({
dataSource: {
transport: {
read: {
url: apiurl,
dataType: "json",
}
}
},
columns: [
{
field: "id",
title: "User Id"
},
{
field: "name",
title: "User Name",
},
{
field: "type",
title: "User Type",
},
{
field: "address.street1",
title: "Street 1",
},
{
field: "address.street2",
title: "Street 2",
},
{
field: "address.postcode",
title: "Street 2",
},
{
field: "address.geo.lat",
title: "Latitude",
},
{
field: "address.geo.long",
title: "Longitude",
}
]
});