-3

I am trying to build a JSON object from a HTML form. My backend API accepts JSON only.

I try uing JSON.stringify but it give me a "1 level object" only. While I need a nested object just like how "multipart/form-data" works

For example I have a formData like this:

product[status]: 1
product[name]: Caesar Warm-Up Pant-32-Black
product[sku]: MP01-32-Black
product[price]: 35.00
product[tax_class_id]: 2
product[quantity_and_stock_status][is_in_stock]: 0

So I want my JSON looks like this

{
    product: {
        status: 1,
        name: "Caesar Warm-Up Pant-32-Black",
        sku: "MP01-32-Black",
        price: 35.00,
        tax_class_id: 2,
        quantity_and_stock_status: {
            is_in_stock: 0
        }
    }
}

Is there any wait to do it with plain javascript or any NodeJS package can do this?

Thank you

Thelearning
  • 89
  • 1
  • 7

0 Answers0