JSON Array is a data structure used to store an ordered list of values, enclosed in square brackets []. It is one of the two fundamental data structures defined by JSON (JavaScript Object Notation), the other being objects.
Structure: A JSON array contains zero or more values, each separated by a comma. The first element is at index
0, and the last element is at indexlength - 1.Data Types: Elements within a JSON array can be of any valid JSON type: strings, numbers, booleans, null, objects, or even nested arrays.
Example:
[ "apple", 42, true, null, { "name": "John", "age": 30 }, [1, 2, 3] ]Usage: JSON arrays are commonly used to represent lists of items, such as user roles, product IDs, or configuration settings. They are supported in JavaScript, SQL (via functions like
JSON_ARRAY), Java (viaJsonArrayinterface), and many other programming languages and databases.Key Features:
Ordered: The sequence of elements matters.
Heterogeneous: Can mix different data types.
Accessible via index: Use
[index]to retrieve elements (e.g.,array[0]).
Common Use Cases:
Storing lists of strings:
["red", "green", "blue"]Representing arrays of objects:
[{"id": 1}, {"id": 2}]Nested arrays:
[[1, 2], [3, 4]]
In SQL: Functions like
JSON_ARRAY()in MySQL, SQL Server, Oracle, and others allow generating JSON arrays from SQL expressions.In Code: In JavaScript, JSON arrays are nearly identical to JavaScript arrays. In Java, the
JsonArrayinterface from the Java EE API provides immutable access to JSON arrays.
I'll elaborate a bit more on ChrisR awesome answer and bring images from his awesome reference.
A valid JSON always starts with either curly braces { or square brackets [, nothing else.
{ will start an object:

{ "key": value, "another key": value }
Hint: although javascript accepts single quotes
', JSON only takes double ones".
[ will start an array:

[value, value]
Hint: spaces among elements are always ignored by any JSON parser.
And value is an object, array, string, number, bool or null:

So yeah, ["a", "b"] is a perfectly valid JSON, like you could try on the link Manish pointed.
Here are a few extra valid JSON examples, one per block:
{}
[0]
{"__comment": "json doesn't accept comments and you should not be commenting even in this way", "avoid!": "also, never add more than one key per line, like this"}
[{ "why":null} ]
{
"not true": [0, false],
"true": true,
"not null": [0, 1, false, true, {
"obj": null
}, "a string"]
}
Answer from cregox on Stack OverflowI'll elaborate a bit more on ChrisR awesome answer and bring images from his awesome reference.
A valid JSON always starts with either curly braces { or square brackets [, nothing else.
{ will start an object:

{ "key": value, "another key": value }
Hint: although javascript accepts single quotes
', JSON only takes double ones".
[ will start an array:

[value, value]
Hint: spaces among elements are always ignored by any JSON parser.
And value is an object, array, string, number, bool or null:

So yeah, ["a", "b"] is a perfectly valid JSON, like you could try on the link Manish pointed.
Here are a few extra valid JSON examples, one per block:
{}
[0]
{"__comment": "json doesn't accept comments and you should not be commenting even in this way", "avoid!": "also, never add more than one key per line, like this"}
[{ "why":null} ]
{
"not true": [0, false],
"true": true,
"not null": [0, 1, false, true, {
"obj": null
}, "a string"]
}
Your JSON object in this case is a list. JSON is almost always an object with attributes; a set of one or more key:value pairs, so you most likely see a dictionary:
{ "MyStringArray" : ["somestring1", "somestring2"] }
then you can ask for the value of "MyStringArray" and you would get back a list of two strings, "somestring1" and "somestring2".
How to write a simple array in json?
Can a JSON file start with an array instead of an object?
Problems in understand top-level-JSON-array
Hi guys, how do I loop through an array in json, and put values in another array using logstash?
Videos
The JSON for that array is:
["apple","orange","cat","dog"]
JSON for arrays is the same as Javascript array literals, except that JSON doesn't allow missing elements or an optional trailing comma. And the elements of the array have to be valid JSON, so you have to use double quotes around strings, you can't use single quotes like Javascript allows.
You generally shouldn't have to worry about how to format JSON yourself, most languages have library functions that do it for you. In JS you use JSON.stringify, in PHP you use json_encode().
You can convert the array into json by JSON.stringify
var array_list=['apple','orange','cat','dog'];
var json_string = JSON.stringify(array_list);
And using JSON.parse you can parse the JSON
var obj = JSON.parse(json_string);
DEMO
It's been my experience that most if not all of them start with a curly brace. I've been looking into json decoding/encoding in Python, and it got me wondering if a json file could start with a square bracket instead.