1

I'm trying to do a post request with an object inside an object. My JSON body should look like this:

{ "name": "Dish name",
     "description": "Dish description",
     "allergies": "Dish allergies",
     "price": "12",
     "category": { "id": "1", 
                   "name":"Category name", 
                   "description": "Category description" 
                 },
     "image":"adasd"
}

First I JSON.stringify the category object then I create the whole object using the useForm hook in React, after the submit the object creates succesfully but the category has backslashes. I can try to remove the backslashes but he keeps wrapping the object in " " it will look like this:

"category": "{ "id": "1", 
                 "name":"Category name", 
                 "description": "Category description" 
               }",

If I try to post this body it will give an error because it is not seen as an object.

How can I bypass this effect does someone know?

Milofow
  • 11
  • 1

0 Answers0