Legacy Dev Forum Posts

 View Only

Sign Up

Need to include null value in the response when the API doesn't give any values

  • 1.  Need to include null value in the response when the API doesn't give any values

    Posted 06-05-2025 18:33

    Jarvish | 2025-02-20 13:34:08 UTC | #1

    Hi All,

    I have an API which gives the below raw response,

    { "total": 5, "data": [ { "worker": { "descriptor": "Dummy name", "id": "9e4bae7b012b01d0c97f1ab726089393" }, "unit": { "descriptor": "Hours", "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb" }, "absencePlan": { "timeoffs": "(Discretionary Day)", "descriptor": "Discretionary Day", "id": "9f87f860702d108b8efd3c6723349928" }, "category": { "descriptor": "Time Off Plan", "id": "8cdc5bb54494100018789cabb3df006d" }, "effectiveDate": "2025-02-21" }, { "worker": { "descriptor": "Dummy name", "id": "9e4bae7b012b01d0c97f1ab726089393" }, "unit": { "descriptor": "Hours", "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb" }, "absencePlan": { "timeoffs": "(Diversity Celebration Day)", "descriptor": "Diversity Celebration Day", "id": "7219002ea3ed010e3ed3025bfc01eec7" }, "category": { "descriptor": "Time Off Plan", "id": "8cdc5bb54494100018789cabb3df006d" }, "effectiveDate": "2025-02-21", "quantity": "8" }, { "worker": { "descriptor": "Dummy name", "id": "9e4bae7b012b01d0c97f1ab726089393" }, "unit": { "descriptor": "Hours", "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb" }, "absencePlan": { "timeoffs": "(Unpaid Leave - PTO, Protected/Sick Time, PTO)", "descriptor": "PTO", "id": "9f87f860702d108b8efd482c5a04992e" }, "category": { "descriptor": "Time Off Plan", "id": "8cdc5bb54494100018789cabb3df006d" }, "effectiveDate": "2025-02-21", "quantity": "184" }, { "worker": { "descriptor": "Dummy name", "id": "9e4bae7b012b01d0c97f1ab726089393" }, "unit": { "descriptor": "Hours", "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb" }, "absencePlan": { "descriptor": "Vaccine/Wellness Time", "id": "d560d355351d01aab570df4f8754ae73", "timeoffs": "(Vaccine/Wellness Time)" }, "category": { "descriptor": "Time Off Plan", "id": "8cdc5bb54494100018789cabb3df006d" }, "effectiveDate": "2025-02-21", "quantity": "4" }, { "worker": { "descriptor": "Dummy name", "id": "9e4bae7b012b01d0c97f1ab726089393" }, "unit": { "descriptor": "Hours", "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb" }, "absencePlan": { "timeoffs": "(Volunteer Time)", "descriptor": "Volunteer Time", "id": "9f87f860702d108b8efd557de9ac9938" }, "category": { "descriptor": "Time Off Plan", "id": "8cdc5bb54494100018789cabb3df006d" }, "effectiveDate": "2025-02-21", "quantity": "40" } ] }

    if you take a close look for the first item we don't have anything called quantity, if we are not getting any fields like this I want to take it as 0/null using translation mapping.

    Current translation mapping which I have is below:

    { "translationMap": { "timeOffType": "$.data[].absencePlan.id", "balance": "$.data[].quantity" }, "translationMapDefaults": { "timeOffType": "UNKNOWN", "balance": "UNKNOWN" }, "successTemplate": "{ \"timeOffType\": ${timeOffType}, \"balance\": ${balance} }" } Current Response: { "timeOffType": [ "9f87f860702d108b8efd3c6723349928", "7219002ea3ed010e3ed3025bfc01eec7", "9f87f860702d108b8efd482c5a04992e", "d560d355351d01aab570df4f8754ae73", "9f87f860702d108b8efd557de9ac9938" ], "balance": [ "8", "184", "4", "40" ] } Expected Response: { "timeOffType": [ "9f87f860702d108b8efd3c6723349928", "7219002ea3ed010e3ed3025bfc01eec7", "9f87f860702d108b8efd482c5a04992e", "d560d355351d01aab570df4f8754ae73", "9f87f860702d108b8efd557de9ac9938" ], "balance": [ "NA"/"0"/null "8", "184", "4", "40" ] }

    Kindly look into this and let me know your thoughts on this.

    Regards, Jarvish Kisanth Singh


    Jarvish | 2025-02-24 18:18:17 UTC | #2

    Hi All,

    Can someone help me on this?

    Regards, Jarvish Kisanth Singh


    Jerome.Saint-Marc | 2025-02-26 15:02:55 UTC | #3

    Hello,

    I don't think it is possible to capture this missing balance quantity as null/O.

    The Data Action translation map entries you have defined are JSONPath expressions (Data Actions leverage JSONPath). If you define something like: $.data[*].quantity, JSONPath will only return values from data object which did have a quantity attribute. To get what you want, the data object you want to return O/null would have had to be defined as quantity: null.

    Regards,


    system | 2025-03-28 15:03:20 UTC | #4

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


    This post was migrated from the old Developer Forum.

    ref: 31834