Categories
JavaScript Answers

How to use things other than arrays in nested JSON objects?

Spread the love

Sometimes, we want to use things other than arrays in nested JSON objects.

In this article, we’ll look at how to use things other than arrays in nested JSON objects.

How to use things other than arrays in nested JSON objects?

To use things other than arrays in nested JSON objects, we can use objects and primitive values.

For instance, we write

{
  "data": [
    {
      "stuff": [
        {
          "onetype": [
            { "id": 1, "name": "John Doe" },
            { "id": 2, "name": "Don Joeh" }
          ]
        },
        { "othertype": [{ "id": 2, "company": "ACME" }] }
      ]
    },
    {
      "otherstuff": [
        {
          "thing": [
            [1, 42],
            [2, 2]
          ]
        }
      ]
    }
  ]
}

to create JSON objects that has arrays, objects, and primitive values.

Conclusion

To use things other than arrays in nested JSON objects, we can use objects and primitive values.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *