parseJSON
Dear all,
anybody who can tell me what I do wrong here :
I have a text file with the following content :
{
"invoices[
{
"recipient": "23022",
"date": "",
"credit period": 8,
"message":"Faktura ",
"our reference": "Martin Reslow",
"purchase order": "",
"currency": "DKK",
"exchange rate": "1",
"rounding": true,
"template": "Df",
"show delivery date": true,
"show delivery address": true,
"items":[
{
"product": "1"
"comment": "et eller andet",
"quantity": "1",
"unit": "",
"price": "1350",
}
]
}
]
}
In a formula field I have the following script : parseJSON(textfile) - but nothing happens, and according to the manual for this function the file is invalid if it gives no result.
I would be extremely happy if someone can guide me here - how do I create this JSON file, which I by the way will import to an accounting system.
Thanks
Leo
22 replies
-
Are you trying to get Ninox to create a JSON file?
-
Well, the first line doesn't seem to be right: { "invoices":[
-
can you put this in a formula field and check if you get a right JSON or any errors?
let Xkunde := Kundenavn; this.{ invoices: [ { recipient: text((select Kunder where Kundenavn = Xkunde).'Kundenr.'), date: text(format(Fakturadato, "YYYY-MM-DD")), credit_period: text(first((select Indstillinger).Kreditdage)), message: "Faktura", our_reference: "Martin Reslow", purchase_order: "", currency: "DDK", exchange_rate: 1, rounding: true, template: "Df", show_delivery_date: true, show_delivery_address: true, items: [ { product: 1, comment: "et eller andet", quantity: 1, unit: "", price: text(round(number(('Aftalt pris' + 'Total timepris -tilbagegang' + 'Total materialepris excl. moms') * 1.25), 2)), }], }]}
Maybe if you gave us more info about the used tables and the fields and the relationships, we can finetune your json.
-
A couple of things I've learned as I expand my use of JSON in Ninox:
1) if you create a JSON in Ninox, like in example, then you don't need to parse it. It is already in a valid JSON format. You can use the formula field name in other formulas.
2) if you want to create a JSON then display it in a text field, then you need to use formatJSON(). This converts the JSON into a string. Which is what you need to use to export it into a file if you use method.
3) You only need to use parseJSON() if you JSON data in a text format that you need to convert into a machine readable JSON format.
-
So to finetune your json code more, if you want to use spaces instead of the underscores_ you must put your key names between single quotes, also you need to convert all the numbers to text, using the text() function like you use for the item price.
this.{ invoices: [ { recipient: text(Kundenavn.'Kundenr.'), date: text(format(Fakturadato, "YYYY-MM-DD")), 'credit period': text(first((select Indstillinger).Kreditdage)), message: "Faktura", 'our reference': "Martin Reslow", 'purchase order': "", currency: "DDK", 'exchange rate': "1", rounding: "true", template: "Df", 'show delivery date': "true", 'show delivery address': "true", items: ['invoice lines'.{ product: "1", comment: "et eller andet", quantity: "1", unit: "", price: text(round(number(('Aftalt pris' + 'Total timepris -tilbagegang' + 'Total materialepris excl. moms') * 1.25), 2)), }], }]}
be aware that if you format your numberfield, you sometimes get the numberformatting back if you only use text() function. Meaning you get 5.500,00 DDK for example. To avoid this you can use the number() function within the text() function. e.g.: text(number(unit_price)) In this case you get "5500"
-
that is valid information - thanks
-
apparently the send problem was overload at Ninox - now every thing works
rgds
Leo
Content aside
- Status Answered
- 23 hrs agoLast active
- 22Replies
- 53Views
-
3
Following