On the outermost level, a JSON object starts with a { and end with a }.

Sample data:

{
    "cars": {
        "Nissan": [
            {"model":"Sentra", "doors":4},
            {"model":"Maxima", "doors":4},
            {"model":"Skyline", "doors":2}
        ],
        "Ford": [
            {"model":"Taurus", "doors":4},
            {"model":"Escort", "doors":4}
        ]
    }
}

If the JSON is assigned to a variable called data, then accessing it would be like the following:

data.cars['Nissan'][0].model   // Sentra
data.cars['Nissan'][1].model   // Maxima
data.cars['Nissan'][2].doors   // 2

for (var make in data.cars) {
    for (var i = 0; i < data.cars[make].length; i++) {
        var model = data.cars[make][i].model;
        var doors = data.cars[make][i].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}

Another approach (using an associative array for car models rather than an indexed array):

{
    "cars": {
        "Nissan": {
            "Sentra": {"doors":4, "transmission":"automatic"},
            "Maxima": {"doors":4, "transmission":"automatic"}
        },
        "Ford": {
            "Taurus": {"doors":4, "transmission":"automatic"},
            "Escort": {"doors":4, "transmission":"automatic"}
        }
    }
}

data.cars['Nissan']['Sentra'].doors   // 4
data.cars['Nissan']['Maxima'].doors   // 4
data.cars['Nissan']['Maxima'].transmission   // automatic

for (var make in data.cars) {
    for (var model in data.cars[make]) {
        var doors = data.cars[make][model].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}

Edit:

Correction: A JSON object starts with { and ends with }, but it's also valid to have a JSON array (on the outermost level), that starts with [ and ends with ].

Also, significant syntax errors in the original JSON data have been corrected: All key names in a JSON object must be in double quotes, and all string values in a JSON object or a JSON array must be in double quotes as well.

See:

  • JSON specification
  • JSONLint - The JSON validator
Answer from Matt Coughlin on Stack Overflow
Top answer
1 of 6
188

On the outermost level, a JSON object starts with a { and end with a }.

Sample data:

{
    "cars": {
        "Nissan": [
            {"model":"Sentra", "doors":4},
            {"model":"Maxima", "doors":4},
            {"model":"Skyline", "doors":2}
        ],
        "Ford": [
            {"model":"Taurus", "doors":4},
            {"model":"Escort", "doors":4}
        ]
    }
}

If the JSON is assigned to a variable called data, then accessing it would be like the following:

data.cars['Nissan'][0].model   // Sentra
data.cars['Nissan'][1].model   // Maxima
data.cars['Nissan'][2].doors   // 2

for (var make in data.cars) {
    for (var i = 0; i < data.cars[make].length; i++) {
        var model = data.cars[make][i].model;
        var doors = data.cars[make][i].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}

Another approach (using an associative array for car models rather than an indexed array):

{
    "cars": {
        "Nissan": {
            "Sentra": {"doors":4, "transmission":"automatic"},
            "Maxima": {"doors":4, "transmission":"automatic"}
        },
        "Ford": {
            "Taurus": {"doors":4, "transmission":"automatic"},
            "Escort": {"doors":4, "transmission":"automatic"}
        }
    }
}

data.cars['Nissan']['Sentra'].doors   // 4
data.cars['Nissan']['Maxima'].doors   // 4
data.cars['Nissan']['Maxima'].transmission   // automatic

for (var make in data.cars) {
    for (var model in data.cars[make]) {
        var doors = data.cars[make][model].doors;
        alert(make + ', ' + model + ', ' + doors);
    }
}

Edit:

Correction: A JSON object starts with { and ends with }, but it's also valid to have a JSON array (on the outermost level), that starts with [ and ends with ].

Also, significant syntax errors in the original JSON data have been corrected: All key names in a JSON object must be in double quotes, and all string values in a JSON object or a JSON array must be in double quotes as well.

See:

  • JSON specification
  • JSONLint - The JSON validator
2 of 6
23

A good book I'm reading: Professional JavaScript for Web Developers by Nicholas C. Zakas 3rd Edition has the following information regarding JSON Syntax:

"JSON Syntax allows the representation of three types of values".

Regarding the one you're interested in, Arrays it says:

"Arrays are represented in JSON using array literal notation from JavaScript. For example, this is an array in JavaScript:

var values = [25, "hi", true];

You can represent this same array in JSON using a similar syntax:

[25, "hi", true]

Note the absence of a variable or a semicolon. Arrays and objects can be used together to represent more complex collections of data, such as:

{
    "books":
              [
                {
                    "title": "Professional JavaScript",
                    "authors": [
                        "Nicholas C. Zakas"
                    ],
                    "edition": 3,
                    "year": 2011
                },
                {
                    "title": "Professional JavaScript",
                    "authors": [
                        "Nicholas C.Zakas"
                    ],
                    "edition": 2,
                    "year": 2009
                },
                {
                    "title": "Professional Ajax",
                    "authors": [
                        "Nicholas C. Zakas",
                        "Jeremy McPeak",
                        "Joe Fawcett"
                    ],
                    "edition": 2,
                    "year": 2008
                }
              ]
}

This Array contains a number of objects representing books, Each object has several keys, one of which is "authors", which is another array. Objects and arrays are typically top-level parts of a JSON data structure (even though this is not required) and can be used to create a large number of data structures."

To serialize (convert) a JavaScript object into a JSON string you can use the JSON object stringify() method. For the example from Mark Linus answer:

var cars = [{
    color: 'gray',
    model: '1',
    nOfDoors: 4
    },
    {
    color: 'yellow',
    model: '2',
    nOfDoors: 4
}];

cars is now a JavaScript object. To convert it into a JSON object you could do:

var jsonCars = JSON.stringify(cars);

Which yields:

"[{"color":"gray","model":"1","nOfDoors":4},{"color":"yellow","model":"2","nOfDoors":4}]"

To do the opposite, convert a JSON object into a JavaScript object (this is called parsing), you would use the parse() method. Search for those terms if you need more information... or get the book, it has many examples.

🌐
Reddit
reddit.com › r/learnpython › multiple objects in json file
r/learnpython on Reddit: Multiple objects in JSON file
February 5, 2020 -

Hey, i am new to programming and I am trying to decode thousands of JSON files.
Usually there is one object in each JSON file, but for some reason a lot of my files have multiple JSON objects. Some have up to 5 objects.

{
	"testNumber": "test200",
	"device": {
		"deviceID": 4000008

	},
	"user": {
		"userID": "4121412"
	}
}
{
	"testNumber": "test201",
	"device": {
		"deviceID": 4000009

	},
	"user": {
		"userID": "4121232"
	}
}

My code gives me the error: json.decoder.JSONDecodeError: Extra data: line 2 column 1
Because of that I am using except ValueError but I would like to get the data out of these JSON files.

import json
import os

test_dir = r'C:\Users\path\path'
for file in os.listdir(test_dir):
    if 'testNumber' in file:
        try: 
            data = json.load(open(test_dir + '\\' + file, 'r'))  
            print("valid")
        except ValueError: 
               print("Decoding JSON has failed")

Since json.loads and json.load don't work: is there any other way open the JSON file so that I can try to split the content in 2 objects?

Discussions

Get values from JSON object when multiple objects returned | OutSystems
Get values from JSON object when multiple objects returned More on outsystems.com
🌐 outsystems.com
Best way to create multiple JSON Elements?
Trying to create a JSON structure in FileMaker like this: { "Cars" : "[VW, GM, Other]", "First_Name" : "Alan", "Last_Name" : "Jones" } { "Cars" : "[Ford, Lexus, BMW]", "First_Name" : "John", "Last_Name" : "Smith" } I've tried two approaches, but both just give me the last JSON element. More on the.fmsoup.org
🌐 the.fmsoup.org
19
0
June 3, 2020
java - Parse JSON multiple objects - Stack Overflow
Your JSON reponse root is array but you consider your JSON response as JSON object More on stackoverflow.com
🌐 stackoverflow.com
October 1, 2019
JSON Array with multiple json objects and json arrays
hello, I made an API call and I got a json response. I deserialized the json response, so that I have a json object. Now I want to extract some information from the object, but I have not managed to do it. Here is my j… More on forum.uipath.com
🌐 forum.uipath.com
6
0
October 27, 2021
🌐
Adobe
opensource.adobe.com › Spry › samples › data_region › JSONDataSetSample.html
JSON Data Set Sample
We get even more rows than we had in Example 9 because the "topping" path also selected multiple objects in some cases.
🌐
Quora
quora.com › Can-JSON-contain-multiple-objects
Can JSON contain multiple objects? - Quora
Answer (1 of 2): The file is invalid if it contains more than one JSON object. When you try to load and parse a JSON file with multiple JSON objects, each line contains valid JSON, but as a whole, it is not a valid JSON as there is no top-level list or object definition. We can call JSON a valid ...
🌐
YouTube
youtube.com › watch
JSON Basics JSON multiple objects within JSON files - YouTube
JSON Course covers everything from start to finish to get you using JSON quickly!•Learn the basics of JSON •JSON structure data of delivery•basics of JavaScr...
Published: March 25, 2016
🌐
GeeksforGeeks
geeksforgeeks.org › python › extract-multiple-json-objects-from-one-file-using-python
Extract Multiple JSON Objects from one File using Python - GeeksforGeeks
July 23, 2025 - # import required modules import re import json # define re pattern to match Json Object pattern = r'{.*?}' # open a file with open('data.json', 'r') as file: file_cont = file.read() # find all JSON Objectss from a file by passing re pattern json_objs = re.findall(pattern, file_cont) # parse each JSON object for obj_string in json_objs: obj = json.loads(obj_string) print(obj) ... In conclusion, we have explored three different approaches for extracting multiple JSON Objects from one file in Python.
Find elsewhere
🌐
Fmsoup
the.fmsoup.org › questions
Best way to create multiple JSON Elements? - Questions - the.fmsoup.org - Independent FileMaker Forum. Help, Discussions & Answers for Developers and Users
June 3, 2020 - Trying to create a JSON structure in FileMaker like this: { "Cars" : "[VW, GM, Other]", "First_Name" : "Alan", "Last_Name" : "Jones" } { "Cars" : "[Ford, Lexus, BMW]", "First_Name" : "John", "Last_Name" : "Smith…
🌐
CodeProject
codeproject.com › Questions › 1164374 › How-to-add-multiple-object-in-JSON-object-array
How to add multiple object in JSON object/array?
Do not try and find the page. That’s impossible. Instead only try to realise the truth - For those who code; Updated: 1 Jul 2007
🌐
Liquid-technologies
blog.liquid-technologies.com › advanced-data-structures-in-json-part-3-of-4
Advanced Data Structures in JSON: Nested Objects & Arrays
July 4, 2025 - Visualizing these nested structures ... Studio JSON Editor can be invaluable for navigating and understanding complex hierarchies. Often, you need to represent a list or collection of items, where each item is itself a complex entity with multiple attributes. This is achieved using an array of objects...
Top answer
1 of 3
2

Your json fragment is invalid - the last comma breaks the parsing. But the rest of the code is quite workable.

    String res = "[\n" +
            "    {\n" +
            "        \"Class\": \"1\",\n" +
            "        \"school\": \"test\",\n" +
            "        \"description\": \"test\",\n" +
            "        \"student\": [\n" +
            "            \"Student1\",\n" +
            "            \"Student2\"\n" +
            "        ],\n" +
            "        \"qualify\": true,\n" +
            "        \"annualFee\": 3.00\n" +
            "       }\n" +
            "]";

    JSONArray arr = new JSONArray(res);
    for (int i = 0; i < arr.length(); i++) {
        JSONObject block = arr.getJSONObject(i);
        Integer cls = block.getInt("Class");
        System.out.println("cls = " + cls);
        Object school = block.getString("school");
        System.out.println("school = " + school);
        JSONArray students = block.getJSONArray("student");
        System.out.println("student[0] = " + students.get(0));
        System.out.println("student[1] = " + students.get(1));
    }

should output

cls = 1
school = test
student[0] = Student1
student[1] = Student2
2 of 3
1

Your JSON reponse root is array but you consider your JSON response as JSON object

Changing your parsing json code as below

String res=cspResponse.prettyPrint();
    org.json.JSONArray arr = new org.json.JSONArray(res);
    String dataStatus=null;
    for (int i = 0; i < arr.length(); i++) {
        org.json.JSONObject obj=arr.getJSONObject(i);
        dataStatus = obj.getString(key);
        System.out.println("dataStatus is \t" + dataStatus);
        String schoolName = org.getString("school");
        System.out.println("school => " + schoolName);
        org.json.JSONArray students = obj.getJSONArray("student");
        System.out.println("student[0] = " + students.get(0));
        System.out.println("student[1] = " + students.get(1));
    }
🌐
PYnative
pynative.com › home › python › json › python parse multiple json objects from file
Python Parse multiple JSON objects from file | Solve ValueError: Extra data
May 14, 2021 - To parse a JSON file with multiple JSON objects read one JSON object at a time and Convert it into Python dict using a json.loads()
🌐
UiPath Community
forum.uipath.com › help › studio
JSON Array with multiple json objects and json arrays - Studio - UiPath Community Forum
October 27, 2021 - hello, I made an API call and I got a json response. I deserialized the json response, so that I have a json object. Now I want to extract some information from the object, but I have not managed to do it. Here is my json response: { “results”: [ { “group”: { “mediaType”: “chat”, “queueId”: “7a982920-3a-4083-8315-db0f5fec6c44” }, “data”: [ { “interval”: “2021-08-16T00:00:00.000Z/2021-08-22T00:00:00.000Z”, “metrics”: [ { “metric”: “tAcw”, “stats”: { “max”: 800000, “min”: 6000, ...
🌐
Reddit
reddit.com › r/node › how do i get multiple objects from a json file?
r/node on Reddit: How do I GET multiple objects from a JSON file?
June 12, 2020 -

Hi! I'm an absolute beginner trying to create a REST api with node.js, express, and a JSON file following a tutorial online. I'm able to implement all the verbs, but I'm stuck at this part where I want to GET multiple objects from my JSON file. I've tried looking for a way to implement this but I couldn't find any solutions because... I think I'm looking for the wrong thing. I hope someone will be able to help.

I'm using this snippet to GET all the books from the year 2020.

app.get('/books/:year', (req, res) => {
  fs.readFile(dataPath, 'utf8', (err, data) => {
    const bookYear = req.params['year'];
    const bookByYear = JSON.parse(data);
    const book = bookByYear.find(book => book.year === bookYear);
    res.status(200).send(book);
  });
});

However, it returns the first "year" : "2020" object only. How do I get all the objects satisfying the criteria, and not just the first one? Oh and here's my JSON file.

[ {

"title": "ABC", "author": "Author A", "year": "2020" }, { "title": "XYZ", "author": "Author B", "year": "2020" } ]

I feel like I'm missing something small, but I'm too much of a noob to figure anything out... Any help will be appreciated, thank you so much.

🌐
Wappler Community
community.wappler.io › wappler general › need help
Combine multiple objects in one JSON - Need Help - Wappler Community
July 19, 2025 - I have a few queries, and I need to combine all the results into a single large JSON object in the backend. This JSON will be sent to a PDF generation service. Query 1 (Single Query): Deal (information about the opportunity) Query 2 (Single Query): Product_Info (information about the Product linked to the Deal) Query 3 (Single Query): Extended_Product_Info (additional Product details from another table) Query 4 (Multiple Records): Optionals (optional items selected for the Product belonging ...
🌐
Microsoft Power Platform Community
powerusers.microsoft.com › t5 › Building-Flows › Choose-one-JSON-object-from-multiple-based-on-specific-value › td-p › 1442635
Forums | Microsoft Power Platform Community
February 1, 2022 - Quickly search for answers, join discussions, post questions, and work smarter in your business applications by joining the Microsoft Dynamics 365 Community.
🌐
JSON Formatter
jsonformatter.org › ff2448
Multiple JSON objects for multi series chart
Supports JSON Graph View of JSON String which works as JSON debugger or corrector and can format Array and Object.
🌐
Microsoft Learn
learn.microsoft.com › en-ie › answers › questions › 1857170 › deserializing-multiple-object-lists-from-a-json-fi
Deserializing multiple Object Lists from a Json file - Microsoft Q&A
August 7, 2024 - Problem 3, I suspect, is that you have a hierarchy here that isn't correctly represented in the JSON. Your FID type contains a Profile object. Yet profile data is also stored as separate objects. Just given your JSON file there appears to be no reason to actually load the Profile array because your FID objects have the corresponding Profile data already captured.
🌐
GitHub
github.com › danielaparker › jsoncons › blob › master › examples › input › multiple-json-objects.json
jsoncons/examples/input/multiple-json-objects.json at master · danielaparker/jsoncons
A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON - jsoncons/examples/input/multiple-json-objects.json at master · danielaparker/jsoncons
Author: danielaparker