JavaScript arrays are designed to hold data with numeric indexes. You can add named properties to them because an array is a type of object (and this can be useful when you want to store metadata about an array which holds normal, ordered, numerically indexed data), but that isn't what they are designed for.

The JSON array data type cannot have named keys on an array.

When you pass a JavaScript array to JSON.stringify the named properties will be ignored.

If you want named properties, use an Object, not an Array.

const test = {}; // Object
test.a = 'test';
test.b = []; // Array
test.b.push('item');
test.b.push('item2');
test.b.push('item3');
test.b.item4 = "A value"; // Ignored by JSON.stringify
const json = JSON.stringify(test);
console.log(json);

Answer from Quentin on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › stringify
JSON.stringify() - JavaScript | MDN
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
JSON.stringify()
JSON.stringify() can not only convert objects and arrays into JSON strings, it can convert any JavaScript value into a string.
🌐
4D
developer.4d.com › 4d language › commands by theme › json › json stringify array
JSON Stringify array | 4D Docs
var $jsonObject : Object var $jsonString : Text QUERY([Company];[Company]Company Name="a@") OB SET($jsonObject;"company name";->[Company]Company Name) OB SET($jsonObject;"city";->[Company]City) OB SET($jsonObject;"date";[Company]Date_input) OB SET($jsonObject;"time";[Company]Time_input) ARRAY OBJECT($arraySel;0) While(Not(End selection([Company]))) $ref_value:=OB Copy($jsonObject;True) // If you do not copy them, the values will be empty strings APPEND TO ARRAY($arraySel;$ref_value) // Each element contains the selected values, for example: // $arraySel{1} = // {"company name":"APPLE","time":43200000,"city": // "Paris","date":"2012-08-02T00:00:00Z"} NEXT RECORD([Company]) End while $jsonString:=JSON Stringify array($arraySel) // $jsonString = "[{"company name":"APPLE","time":43200000,"city": //"Paris","date":"2012-08-02T00:00:00Z"},{"company name": //"ALMANZA",...}]"
🌐
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.
🌐
Grafana
community.grafana.com › grafana k6 › oss support
Is JSON.stringify() necessary for payloads via Shared Array? - OSS Support - Grafana Labs Community Forums
March 25, 2023 - So im trying to load a .json file into a SharedArray according to the docs here: SharedArray Right now my “load” function looks like this: export function loadData(dataFile) { const data = new SharedArray('dataFile', function () { const obj = JSON.parse(open(dataFile)); return obj; }) return data } Which I then load in my test file via: const data = loadData("/resources/api/cloud-pos-check/cloud-post-check.json"); const body = data[0]; (data[0] above is the JSON object in the...
🌐
DEV Community
dev.to › katherineh › jsonstringify-jsonparse-1585
JSON.stringify() & JSON.parse() - DEV Community
November 18, 2024 - JSON.stringify() converts JavaScript Objects an Arrays into JSON Strings.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-json-stringify-an-array-of-objects-in-javascript
How to JSON Stringify an Array of Objects in JavaScript ? - GeeksforGeeks
August 5, 2025 - Example: The below example uses JSON.stringify with a Replacer Function to JSON stringify an array of objects in JavaScript.
Find elsewhere
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
JSON methods, toJSON
The method JSON.stringify(student) takes the object and converts it into a string.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-json-stringify-method
JavaScript JSON stringify() Method - GeeksforGeeks
July 11, 2025 - The JSON.stringify() method in JavaScript is used to convert JavaScript objects into a JSON string. This method takes a JavaScript object as input and returns a JSON-formatted string representing that object.
🌐
Reddit
reddit.com › r/learnjavascript › why does my array have "extra values". how can i json.stringify this info?
r/learnjavascript on Reddit: Why does my array have "extra values". How can I JSON.stringify this info?
November 29, 2021 -

This is weird but I am using a library that adds additional properties to array objects.

We have a simple array of numbers that looks like this:

[1,2,3,4,5,6]

This library I'm using (developed in house unfortunately) gives us the array but also adds extra props to it. When I console.log the array, what I actually see is:

[1,2,3,4,5,6, low: 1, high: 6, median: 3]

Unfortunately, JSON.stringify causes this info to get lost:

'[1,2,3,4,5,6]'

To make things more difficult, I do not know the exact properties that are "attached" to the array (sometimes its mean, sometimes its something completely domain specific).

How can I deal with these weird data types at runtime such that this info can be sent over the wire? Is it even possible? I imagine it breaks JSON schema of some sort.

Top answer
1 of 3
2
I'm not sure if it's helpful, but you could consider converting the array into an object of some sort so that you don't lose the properties. const arr = [1, 2, 3, 4, 5, 6]; arr.low = 1; arr.high = 6; arr.median = 3; const obj = {}; for (const key in arr) { obj[key] = arr[key]; } console.log(JSON.stringify(obj)); Or you might consider grouping the array together somehow (like if you at least know none of the added properties will be numbers): const arr = [1, 2, 3, 4, 5, 6]; arr.low = 1; arr.high = 6; arr.median = 3; const obj = { arr: [] }; for (const key in arr) { // probably should be more thorough in checking if the key is an integer here... if(!isNaN(key)) { obj.arr.push(arr[key]); continue; } obj[key] = arr[key]; } console.log(JSON.stringify(obj));
2 of 3
1
To add to what ashanev has said, here's some things that might be useful for your research: JSON.stringify() checks for a method called toJSON() , which you can use to create a serialized format for your special objects. If those are in-house, discuss if that would be a useful way forward. If you can't do that for whatever reason, Object.getOwnPropertyNames(obj) can list all the non-inherited properties on an object - even ones that don't show up in iterators like Object.keys(). You'll probably still need to determine what kind of special object it is so you can convert it to the right thing at the other end -- and keep this information updated (which is one reason for the above approach). JSON.parse() takes a reviver function to convert those custom serialized strings back in to the custom objects.
🌐
ZetCode
zetcode.com › javascript › json-stringify
JavaScript JSON.stringify - Converting Objects to JSON
The JSON.stringify method converts a JavaScript object or value to a JSON string. It can optionally modify or filter values if a replacer function/array is specified.
🌐
DhiWise
dhiwise.com › post › javascript-essentials-detailed-exploration-of-json-stringify
Exploring JSON Stringify: An In-Depth Exploration
September 29, 2023 - JSON Stringify is a method in JavaScript that converts JavaScript objects into JSON strings. Learn about JSON Stringify its syntax, and its parameters.
🌐
ServiceNow Community
servicenow.com › community › developer-articles › interesting-facts-about-json-stringify › ta-p › 2329985
Interesting facts about JSON.stringify() - ServiceNow Community
June 5, 2021 - function replacer(key, value) { // Filtering out properties if (typeof value === 'string') { return undefined; } return value; } var foo = {foundation: 'Mozilla', model: 'box', week: 45, transport: 'car', month: 7}; JSON.stringify(foo, replacer); // '{"week":45,"month":7}' If replacer is an array, the array's values indicate the names of the properties in the object that should be included in the resulting JSON string.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › parse
JSON.parse() - JavaScript | MDN
Similar to the replacer parameter of JSON.stringify(), for arrays and objects, reviver will be last called on the root value with an empty string as the key and the root object as the value.
🌐
npm
npmjs.com › package › fast-json-stringify
fast-json-stringify - npm
largeArrayMechanism: set the mechanism that should be used to handle large (by default 20000 or more items) arrays. More details · Build a stringify() function based on jsonschema draft 7 spec.
      » npm install fast-json-stringify
    
Published   Feb 06, 2026
Version   6.3.0
Author   Matteo Collina
🌐
Medium
mahabub-r.medium.com › how-json-stringify-and-json-parse-f455dae70619
How JSON.stringify() and JSON.parse()
May 22, 2025 - function stringifyWithMetadata(obj) { const seen = new WeakMap(); return JSON.stringify(obj, function (key, value) { if (typeof value === "object" && value !== null) { if (seen.has(value)) return { __type: "CircularRef" }; seen.set(value, true); } if (value instanceof Date) { return { __type: "Date", value: value.toISOString() }; } if (value instanceof Map) { return { __type: "Map", value: Array.from(value.entries()) }; } if (value instanceof Set) { return { __type: "Set", value: Array.from(value) }; } return value; }); }
🌐
Online Tools
onlinetools.com › json › stringify-json
Stringify JSON – Online JSON Tools
For example, it can convert a ... It works in the browser and uses the native JSON.stringify() function to get the job done. This function converts elementary values (strings, numbers, constants, booleans), objects, and arrays to a quoted string....