0

Create JSON file for line items

Hi there,

I want to send my invoice data to a third party accounting tool. Therefore, I want to iterate my Ninox invoice line items, transform them to JSON and send the JSON via REST API to the other tool. I don't get how I can create the array of invoice line items. I know how I can define 1 line item, but not how I can create the array with the multiple line items.

My target format:

[{
   item: "1",
   description:"ABC"
  }, {
   item: "2",
   description:"DEF"
  }
]

How do I create / iterate / "fill" my array?

Many thanks!

Fabi

5replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • JSON Data
    formatJSON(jsonObject) - creates a JSON string of a valid JSON object
    parseJSON(jsonString) - reconstructs a JSON object from a valid JSON string. In case of an invalid string, the function returns undefined.

     

    from the Manual.  It may help you. 

    Like
      • Mike
      • ninox.1
      • 7 mths ago
      • Reported - view

      Nick Massie What if you need to extract the parts of the JSON and build up some other kind of structure? Would you use a for loop on the JSON in that case?

      Like
  • You can also use a select funtion e.g.:

    (select invoices).{
    desc : DescriptionField,
    date : format(Datefield, "DD/MM/YYYY"),
    name : NameField,
    adress : Adressfield}

    This gives as result a true JSON format where you can assign customized fieldnames

    Steven

    Like
      • Mike
      • ninox.1
      • 7 mths ago
      • Reported - view

      RoSoft_Steven Rooryck Thanks Steven. If you were replying to my posting, it's not clear how I would read a JSON string in a field using your example and parse it line by line to extract elements. I know you know what you're talking about, I am just not able to follow it without a more complete example. Thanks.

      Like
    • Mike Oh, sorry, didn't read your post in detail. Yes using a loop is a solution e.g.:

      let PJ := parseJSON(YourJSONdataField);
          for i in range(0, cnt(PJ)) do
              let id := number(item(PJ, i).Keyid);
              let nextfield := text(item(PJ, i).PreviousField);
              let newfield := text(item(PJ, i).Oldfield)
      end;
      
      Like 1
Like Follow
  • 7 mths agoLast active
  • 5Replies
  • 562Views
  • 2 Following