Any elegant way to convert table data to JSON?

I need some JSON for a webhook. Specifically I need to convert table data into JSON so I can send multiple line items to a service (each line item would be a table row).

I assume this might be possible using the format() function but wondering if anyone has any examples or clever ways of doing it? (Like a pack - I couldn’t see one!)

This is the most compact way to represent a Coda table as a JSON object:

The formula is…
image

How it works…

  • we use Format() to provide the JSON structure & insert the names & values
  • for each column we provide the column name, and a list of its values
  • so in this example we do that for the Name, Email, Amount, and Notes columns
  • then we use SubstituteAll() to place double quotes around all the commas

We can test this JSON by using ParseJson() with c column name & a row+1
This proves the JSON is formatted correctly.

Max

3 Likes

That is awesome! I’ve sent an access request for the doc to take a closer look but this is very helpful indeed. The one I need to generate has quite a lot of hierarchy - but it sounds like it will be achievable using this method. Cheers!

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