Table data as JSON array

Hi all, I have a table, and I want to send the rows of data as a JSON array, to a PDF generator so that a PDF report can recreate the table as it appears on my bubble page.

here’s the bubble page:

here’s the JSON string I created:

here’s how it looks when the PDF is generating:

I know my JSON is not creating separate items inside the object, and instead is sending a comma separated list to the first row. How can I rewrite the JSON so that each item lands in it’s own row?

Thanks

search line items :arbitrary text to a single text field

inside arbitrary text iterate through each line item like this:

{
“line_items1”: {
“date”: “April 08, 2024”,
“service”: “Rehabilitation”,
“total”: “$150”
}
}
Replace those values for dynamic ones

thank you @cmarchan but I don’t understand what you mean as it relates to the dynamic values I used. Can you please elaborate? Thanks!

I can help you do it, without any charge

thanks again @cmarchan. I still don’t know what you mean. I have dynamic values in my original post. I don’t understand your reference to searching and including arbitrary text.
“line_items1” is the object that will have a dynamic number of entries (each including date,service, total).
Also thanks @Baloshi69

Hi all, does anyone know how to get bubble to insert all the objects “line_items1” from the table data, into JSON, so I can pass that array to the PDF generator API, thus recreating the table in PDF?

the present way I show above just creates 1 object containing lists of each dataset. Thanks!

If you have a static number of rows, follow @cmarchan advice an prepare an expression for EACH line, something like this:

“line_items”: [
{“date”: “Table GetClientPurchases Purchase’s List of GetClientPurchases Purchases: item # 1 Sale SaleDate: formatted as November 8, 2024”, “service”: “Table GetClientPurchases Purchase’s List of GetClientPurchases Purchases: item #1 Description”, “total”: “Table GetClientPurchases Purchase’s List of GetClientPurchases Purchases: item #1 AmountPaid: formatted as $1,028.58”},
// Additional items…
]

But if you have a dynamic number of lines I would recommend create a backend workflow to create a loop and for each line of the table you insert an element in a element.

If you can, share your app for a deep explanation :wink:

Thanks Matt, the table is dynamic so the number of rows will vary. I’ll explore a backend recursive workflow to see if that’s possible.

I have looked into running a backend workflow and there doesn’t seem to be a way to do this. My table will have a dynamic number of rows. I need a way to generate and send the table row info as an JSON object. I would think many people would want this functionality.

@kenny Please take a look at this video and let me know if it works for you!

@matt.braga thank you so much for taking the time to create this workflow and video! It is a very interesting approach. For me one of the hurdles I have is that I’m pulling the history of purchases from an API datasource (as opposed to having list of things in the database). I don’t know if this makes it more complicated or not but I don’t necessarily need to start with the data in a table. what I am doing is calling the API for a customer’s purchase history, and returning the date, type, and amount, then assembling that data in json so the PDF generator can accept the objects and place them correctly.

@kenny I believe you can follow the same structure as the backend workflow I sent over.

If possible, could you share your app for visualization? That way, we can discuss specifics related to your situation.

Have you figured it out?

You need to start by breaking up “TableGetClientPurchases” by using: each item is not empty" format as text, then you can apply your JSON Structure PER item. Right now your structure is sending ALL items in a single row.

Huge thanks to @matt.braga and @cmarchan for the help here. I have found a solution. As @matt.braga suggested, I created a thing to receive the JSON that I created with a recursive workflow. My steps below:

  1. create a datatype “history” with a text field “JSON” as a list.
  2. on the page with my Table, I have a button to start the workflow, the first step is to search for a “history” record (with any contraints you need), then clear out the “JSON” field.
  3. Next step is to schedule a backend workflow: the list to run on is the table, and the parameters are the names of JSON records I want in my array… I add 2 seconds in between recursive loops and schedule it to start 15 seconds after the first step (so I make sure clearing the list was completed first)
  4. The backend workflow makes changes to the "history record, but setting “This JSON” to arbitrary text that contains the JSON string I need… The result is the “JSON” field having a comma separated list of JSON as a string.
  5. The next step is anothe backend workflow that sends the information to the PDF Generator. It works great. Screenshots below.





image

2 Likes