'Multi element JSON object from JavaScript

I have a Javascript JSON object

const student = { name: "bob", age: 7, grade: 6 }

and I can pass it to my Web API using axios POST command by

JSON.stringify(student)

and I can build my student object by looping an array and passing in a value such as

let studentArr= []
const student = { name: studentArr[i]["name"], age: studentArr[i]["age"], grade: studentArr[i]["grade"}

I'm using i in the example as the index because it could have 100 students. As long as I pass in only one value for i, everything works fine. My question is how can I make it into a multi-element JSON object from my array. I've been spoiled by Newtonsoft.Json where I can pull data from a SQL database and create a JSON object. If I just JSON.stringify(studentARR) is shows empty. I want to pass to the Web API all of the students on one post so the Web API can make a document and download it back.

I seen many different ways of trying to accomplish this and the methods seem to change over time. Thanks for the help



Solution 1:[1]

Why do you have to JSON.stringify if you are using axios. The declaration of axios.post accepts URL as first parameter and the data which is formdata or the JSON object as second parameter

I'm pretty sure that you might not need to use JSON.stringify if you are using axios to post to a Web API

Example of using Axios post method https://axios-http.com/docs/post_example

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sathya