JSON - structure parent/child with only one child

Problem with integration. Our customer need JSON data without array mark “[” “]”.
We are using standard API page with XSL transformation + virtual output datastructure.

Standard API output from Origam is:
(there is only one child in structure)

{
    "capacity4": null,
    "capacity1": 0.0,
    "distanceCost": null,
    "maximumDistance": null,
    "mustFinishBy": null,
    "specialCodes": null,
    "capacity5": null,
    "maximumDistancePerLeg": null,
    "destination": [
        {
            "street": "Poděbradská 666",
            "postalCode": "88888",
            "longitudeX": 13.91685,
            "locationId": "Depo Sklad",
            "city": "Jirny",
            "latitudeY": 49.11772
        }
    ],
}

Our partner needs output like this:

{
    "capacity4": null,
    "capacity1": 24000.0,           
    "distanceCost": null,
    "maximumDistance": null,
    "mustFinishBy": null,
    "specialCodes": null,
    "capacity5": null,
    "maximumDistancePerLeg": null,
    "destination": {
        "street": "Poděbradská 666",
        "postalCode": "88888",
        "longitudeX": 13.91685,
        "locationId": "Depo Sklad",
        "city": "Jirny",
        "latitudeY": 49.11772
    },
}

Is there any way to get this output from Origam datapage API ?
Thanks Jiri

This is not possible at the moment. We always write the array:

But we have it under control. The solution (new feature) could be to add an attribute to Data Structure Entity, something like bool JsonArray. If false it could omit the array mark. If the child would contain more than 1 record, it would fail.

Interesting inspiration which JSON styles are used and named with differencies between. GitHub - bramstein/xsltjson: XSLTJSON - Convert XML to JSON using XSLT

It’s prepared, the property name in the data structure entity is named “SerializeAsSingleJsonObject” so that it’s meaning is straightforward and also it has a default value false, which is needed for maintain backward compatibility for added boolean properties

Test has been added to model-tests model repo
/api/public/test-json-serialize-as-object

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.