How to remove 'null' keyword from field value from Payload?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 02:11 AM
Scenario: I am creating an action for payload for integration purpose. In the scripting part i am defining field structure including non mandatory fields as well.
Issue: I dont want to pass 'null' keyword in payload request if field doesn't have any value.
Expected solution: If a field doesn't have any value then simply it show pass like <"">
Sample code which i am using:
{ "PO Header": { "PurchaseOrderItemText": null, "Plant": 1710, "OrderItemCategory": null,
"PriceAmount": null
}
}
Expected Solution:
{ "PO Header": { "PurchaseOrderItemText": "", "Plant": 1710, "OrderItemCategory": "", "PriceAmount": "",
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 02:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2024 02:32 AM
Hi @vishaljaiswal,
To confirm, you're receiving the request with null values. Painful. Ideally, this would be fixed at source, but let's go back to reality and handle it ourselves.
In the past I've replaced the null values similar to the below:
If you're handling the JSON object, then you can use this:
data = JSON.stringify(data).replace(/null/g, '""'); //Turns to string
If you're handling it as a string, you can use this:
data = data.replace(/null/g, '""'); //Stays as string
Or:
data = JSON.parse(data); // Turns to a JSON object
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2024 05:51 AM
Hi @vishaljaiswal,
Did you see my earlier response?
In the past I've replaced the null values similar to the below:
If you're handling the JSON object, then you can use this:
data = JSON.stringify(data).replace(/null/g, '""'); //Turns to string
If you're handling it as a string, you can use this:
data = data.replace(/null/g, '""'); //Stays as string
Or:
data = JSON.parse(data); // Turns to a JSON object
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Helpful.
Thanks, Robbie