There is no need to wrap the array in another object with a data property. The array by itself is valid JSON:

post_params = JSON.stringify([ { 'name' : 'Alice', 'age' : 15 },
                               { 'name' : 'Bob',   'age' : 20 },
                                  ...
                             ]);
post(url, post_params);

Just make sure your API expects this array as well.

Answer from Adam Liechty on Stack Overflow
🌐
Quora
quora.com › How-do-I-send-a-JSON-array-in-a-post-request
How to send a JSON array in a post request - Quora
Answer (1 of 4): What you need to do is to proceed with these steps: 1. Create the JSON Array: First, you need to create the JSON array that you want to send in your POST request. Make sure the data is properly formatted as a valid JSON array. 2. Set Headers: In your POST request, you'll need to...
Discussions

Passing an array in form-data, JSON Format
I am trying to send a POST request with both a FILE upload and some JSON body data. The file is not an issue using the form-data, however I can’t seem to get past the JSON body part regardless of trying everything I can think of. This is the API I’m trying to post to: https://docs.deve... More on community.postman.com
🌐 community.postman.com
1
0
May 14, 2022
POST Request: dynamically send an array (list) in a JSON
Hey everyone, I need to send a POST Request to an API. This post request contains a field “envs”, which contains an array of objects (each of those contains a “key” and a “value” - both strings) (See screenshot). I cannot simply hardcode this information into the request. More on forum.bubble.io
🌐 forum.bubble.io
0
1
February 7, 2022
Post an array in a HTTP request
The steps you have taken Relevant ... "and": "JSON", "in" : "code block"} ] Exclude Personal Information. Hello, I am a bit confused on how to send a Http post so I would appreciate if someone could help me. The API documentation says for required variable: emisor array Required tipodoc ... More on community.make.com
🌐 community.make.com
2
0
June 8, 2023
What is the "best practice" for sending an array of objects to the server?
Assemble the array in your front end, attach the json to your form data and post it. More on reddit.com
🌐 r/webdev
22
17
November 3, 2023
🌐
Postman
community.postman.com › help hub
Passing an array in form-data, JSON Format - Help Hub - Postman Community
May 14, 2022 - Here is what the JSON body should more or less look like: { “key”: “source”, “tabfile”: “string”, “questions”: [ { “index”: “string”, “reportLabel”: “string”, “label”: “string”, “title”: “string”, “type”: “single”, } ] } The issue I keep running into is this 400 error and this regardless of what I try using form-data: ... Basically I can’t figure out how to pass it as an array using form-data and I have no idea if you can use raw to upload a file along with doing the above, so any thoughts/tips/tricks to get this to work would be amazing!
🌐
Bubble
forum.bubble.io › need help › apis
POST Request: dynamically send an array (list) in a JSON - APIs - Bubble Forum
February 7, 2022 - Hey everyone, I need to send a POST Request to an API. This post request contains a field “envs”, which contains an array of objects (each of those contains a “key” and a “value” - both strings) (See screenshot). I cannot simply hardcode this information into the request.
🌐
Daily Coding 7
dailycoding7.com › blog › web-development › how-you-send-a-json-array-in-a-post-request-using-python
How you send a JSON array in a post request using Python 🐍 💻
August 27, 2023 - import requests import json # Your ... 'application/json' } # Send POST request response = requests.post('https://example.com/api/endpoint', data=json_data, headers=headers) # Check the response if response.status_code == ...
🌐
Make Community
community.make.com › questions
Post an array in a HTTP request - Questions - Make Community
June 8, 2023 - $response = $client->post(‘https://www.lioren.cl/api/boletas’, [ ‘headers’ => [ ‘Accept’ => ‘application/json’, ‘Authorization’ => 'Bearer '.$accessToken, ‘Content-Type’ => ‘application/json’ ], ‘body’ => json_encode($data), ]); $responseBody = json_decode((string) $response->getBody(), true); I have tried different configurations and I get a Status code 200 but with an error that says “emisor must be an array” (I believe an array).
Find elsewhere
🌐
Reddit
reddit.com › r/webdev › what is the "best practice" for sending an array of objects to the server?
r/webdev on Reddit: What is the "best practice" for sending an array of objects to the server?
November 3, 2023 -

Short backstory: I learned Angular straight out of uni and thought it might be useful to get some basic knowledge about how the web works on a fundamental level. So I decided to build a small MPA with Go as a backend language.

Now I got to a problem that would be trivial to solve in Angular but I am having trouble solving with server-side rendering:

Imagine a traditional form where I can add and remove items (kind of like a shopping cart) with javascript and once I am done I can click on "Save" and all items are send to the server with a POST request. The special thing is that the items are complex objects with multiple properties, not just strings.

I would prefer to use a form and just submit it, but it feels like this type of complex data does not go well with a form. I know that PHP can handle this kind of structure (https://stackoverflow.com/questions/34313657/html-form-post-an-array-of-objects), but I don't think this is standard, since there doesn't seem to be a way to do this in Go. So is my only choice to send JSON? But how do I transform my input values to JSON?

So the question is this: what is the best practice when I need to send an array of objects to the server and how would a person have solved this 10 or 15 years ago?

🌐
Coderwall
coderwall.com › p › ywtneg › pass-array-through-post-method
Pass array through POST method (Example)
January 4, 2021 - How to pass an array using POST method. First use the function json_encode() to encode the array. Then use htmlspecialchars() to avoid errors caused by the quotes in json.
🌐
Postman
community.postman.com › help hub
JSON Array in POST Body - Help Hub - Postman Community
May 1, 2019 - Hello- I have multiple line items that i’m trying to post. During the GET request, each line item field is stored as a global variable. The problem is that sometimes I have one line item only that I want to post and then the next run of the request I could have two line items that I want to post.
🌐
Retool
community.retool.com › 💬 queries and resources
How do i sent an Array in a JSON POST body without key value pair? - 💬 Queries and Resources - Retool Forum
May 18, 2022 - I basically just need to send an array like this ["a", "b", "c", "d", "e"] But it wants me to map it to something like "data": ["a", "b", "c", "d", "e"] If i don't map it to anything than nothing shows. I can only send an array to this API and nothing else. Can anyone point me in the right ...
🌐
GitHub
github.com › axios › axios › issues › 4394
How to send array of object in post request using axios library · Issue #4394 · axios/axios
January 17, 2022 - ytIDs.map(async function(item) { const video = await youtube.getVideo(item) ytVideosList.push(video) //adding json object inside array } }) console.log(ytVideosList) //showing data inside array console.log(ytVideosList.length) // this shows as zero strange ... The problem is that map function with async and await which make "ytVideosList.push(video)" execute after "console.log". May be you should write like this: ` const ytVideosList = [] const GetVideos = await axios.post(...); const ytIDs = GetVideos.data; const requestList = ytIDs.map(item => youtube.getVideo(item)); const arr = await Promise.all(requestList);// arr is the list you need ytVideosList = arr;// you can handle the data with your business // your another call API
🌐
GitHub
github.com › postmanlabs › postman-app-support › issues › 4082
How to pass the array value inside body of post request · Issue #4082 · postmanlabs/postman-app-support
January 19, 2018 - You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. ... I have created a global array count = ["1","2","3"] I am trying to pass the array inside body as following, { "Data": [{ "count:" "{{count[0]}}" }, { "count:" "{{count[1]}}" }, { "count:" "{{count[2]}}" } ] }
Author: postmanlabs
🌐
Attacomsian
attacomsian.com › blog › javascript-send-json-object-in-http-request
How to send a JSON object as a parameter in HTTP requests in JavaScript
July 24, 2022 - To send a JSON object or an array as a parameter in HTTP requests (GET or POST) in JavaScript, you first need to convert it into an string using the JSON.stringify() method.
Top answer
1 of 3
1
-----------------------------------test.Order.java-----------------------------------

package test;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Order {

@SerializedName("product_id")
@Expose
private String productId;
@SerializedName("qty")
@Expose
private String qty;
@SerializedName("price")
@Expose
private String price;
@SerializedName("total")
@Expose
private String total;
@SerializedName("product_name")
@Expose
private String productName;

public String getProductId() {
return productId;
}

public void setProductId(String productId) {
this.productId = productId;
}

public String getQty() {
return qty;
}

public void setQty(String qty) {
this.qty = qty;
}

public String getPrice() {
return price;
}

public void setPrice(String price) {
this.price = price;
}

public String getTotal() {
return total;
}

public void setTotal(String total) {
this.total = total;
}

public String getProductName() {
return productName;
}

public void setProductName(String productName) {
this.productName = productName;
}

}
-----------------------------------test.TestClass.java-----------------------------------

package test;

import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class TestClass {

@SerializedName("user_id")
@Expose
private String userId;
@SerializedName("username")
@Expose
private String username;
@SerializedName("order")
@Expose
private List<Order> order = null;

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public List<Order> getOrder() {
return order;
}

public void setOrder(List<Order> order) {
this.order = order;
}

}

Use this two Class.Load data to this class. And use GSON Library.

Gson gson= new GSON();
String requiredJson= gson.toJson(testClassObject);
2 of 3
1
    ArrayList<JSONObject> arrayList = new ArrayList<JSONObject>();
    JSONObject postedJSON = new JSONObject();

    try {
        objJSON.put("key", "value");
      // add key value for json formati
    } catch (JSONException e) {
        e.printStackTrace();
    }
    arrayList.add(postedJSON);
    String variable = arrayList.toString();

Send the string to the server

Learn REST API for POST Sending HTTP POST Request In Java Reference post: Ferrybig answer