When asking your question, please include:
The steps you have taken
Relevant screenshots
Any links you have
[ Code { "and": "JSON", "in" : "code block"} ]
Exclude Personal Information.
Dear Fellow Makers,
I am currently working on a project using Make to connect an application with Sage Accounting. I need to create a JSON string like this:
{
“purchase_invoice”: {
“contact_id”: “07327bf602d5404a833c4588581a1011”,
“currency_id”: “GBP”,
“date”: “2022-12-08”,
“due_date”: “2023-01-07”,
“invoice_lines”: [
{
“analysis_type_categories”: [{
“id”: “dfeb4ad30a454a99b2479939e7b17cbf”}
],
“description”: “MONITOR 27 INCH 4K UHD”,
“ledger_account_id”: “4c93d562add011ed84fa0252b90cda0d”,
“net_amount”: 870,
“quantity”: 3,
“tax_amount”: 174,
“tax_rate_id”: “GB_STANDARD”,
“total_amount”: 1044,
“unit_price”: 290
},
{
“analysis_type_categories”: [{
“id”: “dfeb4ad30a454a99b2479939e7b17cbf”}
],
“description”: “Keyboard Cherry Stream”,
“ledger_account_id”: “4c93d562add011ed84fa0252b90cda0d”,
“net_amount”: 148.15,
“quantity”: 5,
“tax_amount”: 29.63,
“tax_rate_id”: “GB_STANDARD”,
“total_amount”: 177.78,
“unit_price”: 29.63
},
{
“analysis_type_categories”: ,
“description”: “Mouse Logitech M185”,
“ledger_account_id”: “4c93d562add011ed84fa0252b90cda0d”,
“net_amount”: 135.84,
“quantity”: 8,
“tax_amount”: 27.17,
“tax_rate_id”: “GB_STANDARD”,
“total_amount”: 163.01,
“unit_price”: 16.98
}
],
“reference”: “D009921”,
“vendor_reference”: “115496712-3”
}
}
The field of interest is the field “analysis_type_categories”. The id comes from an array aggregator which is populated from an iterator. If the array field is empty the “analysis_type_categories” need to be , if the id is available the “analysis_types_categories” need to be [{“id”: “”}]. I tried various orders of parsing and creating JSON. I tried
- ifempty(;null|emptystring|space)
With an array definition with item of type text it created
“analysis_type_categories”:[null]
With an array definition with item as collection of id’s of type text it created
“analysis_type_categories”:[
{“id”: null}]
Both outputs are correct but unfortunately not accepted by Sage. - Building the JSON string myself
With an array definition with an item of type text and the input
“analysis_type_categories”:[if (id=Null);space;"{“id”: “”}] I am getting
"analysis_type_categories":[if (id=Null);space;"{"id": ""]
Again, correct formatting but not what I need.
Any idea is very much appreciated.
Thanks a lot.
Stefan