How to generate valid JSON in a formula?

I’m trying to create a weweb formula that results in the following JSON:

[{

“price”:"price_1PlsdMDfnldOq1pUl41mWnXd,

“quantity”:“1”

}]

or a description of the issue below.

I asked Copilot how to do it, and at first it gave me this formula:

createObject(

  "price", "price_1PlsdMDfnldOq1pUl41mWnXd",

  "quantity", "1"

)

…which resulted in invalid JSON because it lacked the square & curly brackets.

After a followup question, Copilot told me to use this formula:

"[{"price":"price_1PlsdMDfnldOq1pUl41mWnXd","quantity":“1"}]”

…which resulted in “invalid or unexpected token.”

I tried concatenation, but couldn’t get a working formula.

What should my formula be? Any help would be appreciated!

Hey, this should be a correct format for a JSON object. I’m not sure about the quantity though, as you’re passing it as a string, where as it might want it as a plain integer, without double quotes.

If you want to pass it as an [array] containing one {object}, it would indeed look as you sent it above, simply (don’t mind the expected format - I’m binding to a random thing):

The invalid or unexpected token most likely comes from you inputting the JSON with the double quotes as well.

1 Like

thanks @Broberto