Script for backward-compatibility: https://github.com/douglascrockford/JSON-js/blob/master/json2.js

And call:

var myJsonString = JSON.stringify(yourArray);

Note: The JSON object is now part of most modern web browsers (IE 8 & above). See caniuse for full listing. Credit goes to: @Spudley for his comment below

Answer from JonoW on Stack Overflow
🌐
ReqBin
reqbin.com › code › javascript › n2ek7onb › javascript-array-to-json-example
How do I convert JavaScript array to JSON?
To convert a JavaScript array to a JSON data string, you can use the JSON.stringify(value, replacer, space) method. The optional replacer parameter is a function that can alter the behavior of the serialization process.
Discussions

Javascript array to JSON
🌐 forum.jquery.com
JavaScript array to JSON - JavaScript - SitePoint Forums | Web Development & Design Community
Hey guys, I have a JavaScript array, which I want to convert to JSON. The thing is that I don’t know what will be in the array, cause it’s a calculator, that depends on the user. I saw some commands that parse js to json, but the thing is that I want to be able to use a VARIABLE instead ... More on sitepoint.com
🌐 sitepoint.com
0
October 13, 2017
Converting an array to a JSON object with custom key names
With and without Babel: https://jsfiddle.net/srxs4mcw/ The Babel summary: var arr = ["first", "second", "third", "fourth"]; var keys = ['one', 'two', 'three', 'four']; const newArr2 = arr.reduce((acc, val, i) => ({ ...acc, [keys[i]]: val }), {}); You reduce your array starting with an empty object. Each iteration spreads the accumulated object and adds the new array item to it. This one requires Babel to transpile your code. In my jsfiddle you'll also see a vanilla JS solution which is basically the same thing. More on reddit.com
🌐 r/webdev
6
3
April 21, 2017
Cannot access fields from a json array object with javascript
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch More on reddit.com
🌐 r/learnjavascript
8
1
July 1, 2022
🌐
Boot.dev
boot.dev › blog › javascript › converting an array to a json object in javascript
Converting an Array to a JSON Object in JavaScript | Boot.dev
October 1, 2022 - The JSON.stringify() method converts a JavaScript object, array, or value to a JSON string.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript - MDN Web Docs
1 week ago - The JSON.stringify() static method converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.
🌐
W3Schools
w3schools.com › js › js_json_stringify.asp
JavaScript JSON.stringify()
The JSON.stringify() method converts a JavaScript value into JSON text. JavaScript variables must be converted to plain text before they can be:
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-convert-an-array-to-json
Convert an Array to JSON in JavaScript - GeeksforGeeks
October 7, 2024 - Example 1: This example converts the JS array to JSON String using JSON.stringify() method. ... <!DOCTYPE html> <html> <head> <title> JavaScript | Convert array to JSON.
Find elsewhere
🌐
Medium
medium.com › @louistrinh › converting-data-structures-in-javascript-arrays-to-json-objects-fe2cfc53cdf6
Converting Data Structures in JavaScript: Arrays to JSON Objects | by Louis Trinh | Medium
December 12, 2024 - const twoDArray = [ ["apple", "banana"], ["cherry", "date"], ]; const jsonObj = {}; for (let i = 0; i < twoDArray.length; i++) { jsonObj[`row_${i}`] = twoDArray[i]; } console.log(jsonObj); // Output: { row_0: ["apple", "banana"], row_1: ["cherry", "date"] } ... When converting arrays to JSON objects using indexes as keys, keep in mind that JSON object keys must be strings.
🌐
Jsonjson
jsonjson.com › array-to-json
Array To Json Converter | JsonJson.com
Convert JavaScript arrays to JSON format with this simple online tool.
🌐
DEV Community
dev.to › bootdotdev › converting-an-array-to-json-object-in-javascript-3af4
Converting an Array to JSON Object in JavaScript - DEV Community
January 12, 2021 - The JSON.stringify() method converts a JavaScript object, array or value to a JSON string that can be sent over the wire using the Fetch API (or another communication library).
🌐
TutorialsPoint
tutorialspoint.com › article › javascript-convert-an-array-to-json
JavaScript Convert an array to JSON
March 15, 2026 - JSON.stringify() handles different array types as follows: ... The JSON.stringify() method provides a simple and effective way to convert JavaScript arrays into JSON strings.
🌐
W3Schools
w3schools.com › js › js_json_server.asp
<h1>JavaScript Loading JSON</h1>
The fetch() method can also send JSON to a web server. Use the POST method to send new data. Convert the JavaScript object to JSON text with JSON.stringify().
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › parse
JSON.parse() - JavaScript - MDN Web Docs
July 20, 2025 - The Object, Array, string, number, boolean, or null value corresponding to the given JSON text. ... Thrown if the string to parse is not valid JSON. JSON.parse() parses a JSON string according to the JSON grammar, then evaluates the string as if it's a JavaScript expression.
🌐
ConvertSimple
convertsimple.com › home › convert javascript object to json
Convert Javascript Object to JSON - ConvertSimple.com
October 17, 2020 - Paste your JavaScript Object input into the left input box and it will automatically convert it into JSON. The JSON output is the box to the right.
🌐
ReqBin
reqbin.com › code › javascript › x1ezvres › javascript-object-to-json-example
How do I convert object to JSON in JavaScript?
You can use the JSON.stringify() method to convert a JavaScript array to a JSON data string.
🌐
Convertonline
convertonline.io › convert › js-to-json
Convert Javascript to JSON
Free online based tool to convert Javascript Object or Array to JSON
🌐
SitePoint
sitepoint.com › javascript
JavaScript array to JSON - JavaScript - SitePoint Forums | Web Development & Design Community
October 13, 2017 - Hey guys, I have a JavaScript array, which I want to convert to JSON. The thing is that I don’t know what will be in the array, cause it’s a calculator, that depends on the user. I saw some commands that parse js to j…
🌐
Reddit
reddit.com › r/webdev › converting an array to a json object with custom key names
r/webdev on Reddit: Converting an array to a JSON object with custom key names
April 21, 2017 -

I have an array of strings that I'd like to convert to a JSON object with custom keys.

//Original array
var arr = ["first", "second", "third", "fourth"];

//Preferred JSON format with custom key names
{
  "entries": [
  {
  "one": "first",
  "two": "second",
  "three": "third",
  "four": "fourth"
  }
 ]
}

Struggling to figure this out. Any help would be greatly appreciated.