I'm assuming you're making a POST request with a JSON payload. First, you want to make sure your payload is formatted JSON correctly, use: http://pro.jsonlint.com/

Secondly, you can send the payload using JSON.stringify and you will want to set the contentType:

data: JSON.stringify(data), contentType: "application/json; charset=utf-8"

If you run this and look at your network tab in Dev Tools in Chrome, it will error out, but you will at least see the payload formatted to send to the server: http://prntscr.com/f8hf6s

var data = [{
    "key": "myKey",
    "keyName": "myKeyName",
    "value": "value",
    "valueName": "valueName"
  },
  {
    "key": "mySecondKey",
    "keyName": "mySecondKeyName",
    "value": "secondValue",
    "valueName": "secondValueName"
  }
];

var url = "http://swapi.co/api/";

$.ajax({
  type: "POST",
  url: url,
  data: JSON.stringify(data),
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  error: function() {
    alert("Error");
  },
  success: function() {
    alert("OK");
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Answer from Woodrow on Stack Overflow
Discussions

html - How to post array / data structure via javascript? - Stack Overflow
I'm using HTML & JavaScript at the client side, and NodeJs as the server side. I have a form which contains several radio buttons. When the client click on submit button, I want to send (post... More on stackoverflow.com
🌐 stackoverflow.com
September 2, 2015
Sending a JavaScript array to PHP via POST - Stack Overflow
pythonjavascriptc#reactjsjavaa...gularnext.jsspring-bootmachine-learningsqlexceliosazuredocker ... Next You’ll be prompted to create an account to view your personalized homepage. Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. I am trying to send a JavaScript array to a PHP file ... More on stackoverflow.com
🌐 stackoverflow.com
April 23, 2017
jQuery post array
Am wondering how to post an array using $.ajax. More on stackoverflow.com
🌐 stackoverflow.com
July 15, 2013
javascript - axios post array data
I'm trying to send post request to a server I don't have much control on it. The only thing I know is I can obtain the correct response if I post the following data in Postman x-www-form-urlencoded More on stackoverflow.com
🌐 stackoverflow.com
🌐
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.
🌐
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...
Find elsewhere
🌐
Makitweb
makitweb.com › home › ajax › how to send javascript array to the ajax using jquery and php
How to Send JavaScript Array to the AJAX using jQuery and PHP - Makitweb
December 21, 2023 - $(document).ready(function(){ // submit button click $("#submit").click(function(){ var name = $("#txt_name").val(); var email = $("#txt_email").val(); var lang = []; // Initializing array with Checkbox checked values $("input[name='prolang']:checked").each(function(){ lang.push(this.value); }); if(email != ''){ $.ajax({ url: 'getData.php', type: 'post', data: {name:name,email:email,lang:lang}, dataType: 'JSON', success: function(response){ $('.details').show(); // selecting values from response Object var name = response.name; var email = response.email; var lang = response.lang; var foundjquery = response.foundjquery; // setting values $('#name').text(name); $('#email').text(email); $('#lang').text(lang); $('#foundjquery').text(foundjquery); } }); } }); });
🌐
Stack Overflow
stackoverflow.com › questions › 27050616 › post-array-list-in-js
post array list in js
function crearTodo(nuevoTodo){ var url = API_URL; var todo = JSON.stringify(nuevoTodo); $("#button_to_create").click(function(e){ $("#create_result").text(''); e.preventDefault(); var nuevoTodo ; if($('#id_to_create').val() == "" || $('#summary_to_create').val()==""){ $('<div class="alert alert-info">Debes rellenar los campos ID y summary</div>').appendTo($("#create_result")); }else if (isNaN($('#id_to_create').val())){ $('<div class="alert alert-info">La ID del nuevo TODO debe ser numerica </div>').appendTo($("#create_result")); }else{ nuevoTodo = { "id" : $("#id_to_create").val(), "descripti
🌐
DaniWeb
daniweb.com › programming › web-development › threads › 197159 › how-do-i-pass-arrays-in-javascript-to-php-using-post-method
how do i pass arrays in javascript to php using POST method
June 12, 2009 - The good news for non-json folks is that standard javascript is also very compact for an indexed array comprising numbers or strings or a mixture of the two. It gets more complex if it contains objects and/or is associative, but not insurmountable. ... Choose a delimiter that will never appear in your arrays. It can be multiple characters if you want, eg, delimiter = '£%^&'; . Then use the most appropriate technique for building your post (ie HTML form vs ajax http request object).
🌐
Laracasts
laracasts.com › discuss › channels › laravel › how-to-send-array-from-script-to-controler
how to send array from script to controler
<script type="text/javascript"> function sendData() { var data = [ 1, 2, 3 ]; $.ajax({ url:'/test', type: 'POST', dataType:'json', contentType: 'json', data: JSON.stringify(data), contentType: 'application/json; charset=utf-8', }); } </script>
🌐
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).