# How to generate valid JSON in a formula?

**URL:** <https://community.weweb.io/t/how-to-generate-valid-json-in-a-formula/10208>\
**Category:** How do I?\
**Created:** [August 12, 2024, 7:56pm UTC](https://community.weweb.io/t/how-to-generate-valid-json-in-a-formula/10208 "2024-08-12T19:56:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fredo22](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/fredo22/32/2283_2.png) [@fredo22](https://community.weweb.io/u/fredo22)\
**Post date:** [August 12, 2024, 7:56pm UTC](https://community.weweb.io/t/how-to-generate-valid-json-in-a-formula/10208/1 "2024-08-12T19:56:48Z")

</div>

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

[{

“price”:"price\_1PlsdMDfnldOq1pUl41mWnXd,

“quantity”:“1”

}]

https://www.loom.com/embed/5a5cba68487840c59ea56b073e142ae5?sid=6d0ead90-0a86-43ed-8697-bf8f634ed30b

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!

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [August 12, 2024, 8:15pm UTC](https://community.weweb.io/t/how-to-generate-valid-json-in-a-formula/10208/2 "2024-08-12T20:15:28Z")

</div>

![Screenshot 2024-08-12 at 22.14.46](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/c/cdb9c3a14c657539f148027c3acf6812ded207d7.png)

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):

 ![Screenshot 2024-08-12 at 22.17.12](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/5/50d065ff0b75c58ce0bff59830e11483a4846f62.png)

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

---

<div class="post-metadata">

**Author:** ![fredo22](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/fredo22/32/2283_2.png) [@fredo22](https://community.weweb.io/u/fredo22)\
**Post date:** [August 12, 2024, 9:20pm UTC](https://community.weweb.io/t/how-to-generate-valid-json-in-a-formula/10208/3 "2024-08-12T21:20:03Z")

</div>

thanks @Broberto
