Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8420751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:56:36+00:00 2026-06-10T02:56:36+00:00

I am very much new to this JSON objects. So I need some helps

  • 0

I am very much new to this JSON objects. So I need some helps from you guys. I have to create a JSON object and that object has two children. One child has some children. If my question is confusing just refer the following diagram. It is similar to nested lists.
Example:

PRODUCT_LIST

<ul>
    <li>CATEGORY_ID - A</li>
    <li>PRODUCT_DETAILS
        <ul>
            <li>PRODUCT_ID - A.1</li>
            <li>PRODUCT_NAME - AAAA1111</li>
            <li>UNIT_COST - 0.1</li>
        </ul>
    </li>
    <li>CATEGORY_ID - B</li>
    <li>PRODUCT_DETAILS
        <ul>
            <li>PRODUCT_ID - B.1</li>
            <li>PRODUCT_NAME - BBBBB1111</li>
            <li>UNIT_COST - 0.2</li>
        </ul>
    </li>
</ul>

I tried to do but got JavaScript errors. Can any one please help to create JSON for the above mentioned diagram.
Note: One Category has more than one product details. It means PRODUCT_ID, PRODUCT_NAME and UNIT_COST will be repeating to more than one time for a particular CATEGORY_ID.

The JavaScript code I have tried

var product =   '{"products_list":' +
                '[' + 
                    '{' + 
                        '{"category_id":"A"},' +
                        '{"product_details":' + 
                            '[' + 
                                '{"product_id":"A.1","product_name":"AAAA1111", "unit_cost":"A1"},' +
                                '{"product_id":"A.2","product_name":"AAAA2222", "unit_cost":"A2"},' +
                                '{"product_id":"A.3","product_name":"AAAA3333", "unit_cost":"A3"},' +
                                '{"product_id":"A.4","product_name":"AAAA4444", "unit_cost":"A4"},' +
                                '{"product_id":"A.5","product_name":"AAAA5555", "unit_cost":"A5"},' +
                                '{"product_id":"A.6","product_name":"AAAA6666", "unit_cost":"A6"},' +
                                '{"product_id":"A.7","product_name":"AAAA7777", "unit_cost":"A7"},' +
                                '{"product_id":"A.8","product_name":"AAAA8888", "unit_cost":"A8"},' +
                                '{"product_id":"A.9","product_name":"AAAA9999", "unit_cost":"A9"},' +
                                '{"product_id":"A.0","product_name":"AAAA0000", "unit_cost":"A0"}' +
                            ']' + 
                        '}' + 
                    '},' + 
                    '{' + 
                        '{"category_id":"A"},' +
                        '{"product_details":' + 
                            '[' + 
                                '{"product_id":"A.1","product_name":"AAAA1111", "unit_cost":"A1"},' +
                                '{"product_id":"A.2","product_name":"AAAA2222", "unit_cost":"A2"},' +
                                '{"product_id":"A.3","product_name":"AAAA3333", "unit_cost":"A3"},' +
                                '{"product_id":"A.4","product_name":"AAAA4444", "unit_cost":"A4"},' +
                                '{"product_id":"A.5","product_name":"AAAA5555", "unit_cost":"A5"},' +
                                '{"product_id":"A.6","product_name":"AAAA6666", "unit_cost":"A6"},' +
                                '{"product_id":"A.7","product_name":"AAAA7777", "unit_cost":"A7"},' +
                                '{"product_id":"A.8","product_name":"AAAA8888", "unit_cost":"A8"},' +
                                '{"product_id":"A.9","product_name":"AAAA9999", "unit_cost":"A9"},' +
                                '{"product_id":"A.0","product_name":"AAAA0000", "unit_cost":"A0"}' +
                            ']' + 
                        '}' + 
                    '}' + 
                ']' + 
            '}';
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:56:37+00:00Added an answer on June 10, 2026 at 2:56 am

    Using the HTML tree, you will get the followin JSON representation for the PRODUCT_LIST:

    [
       {
          "CATEGORY_ID":"A",
          "PRODUCT_DETAILS":[
             {
                "PRODUCT_ID":"A.1",
                "PRODUCT_NAME":"AAAA1111",
                "UNIT_COST":0.1
             }
          ]
       },
       {
          "CATEGORY_ID":"B",
          "PRODUCT_DETAILS":[
             {
                "PRODUCT_ID":"B.1",
                "PRODUCT_NAME":"BBBBB1111",
                "UNIT_COST":0.2
             }
          ]
       }
    ]
    

    However, your JavaScript produces a nearly valid JSON string, which is assigned to the product variable. You could use JSON.parse() on it, but that’s too complicated. As the JavaScriptObjectNotation is a subset of the Javascript object literal syntax, you should directly assign the object.

    In your JSON, you have some braces too much around the category objects. You can check that e.g. with http://jsonformatter.curiousconcept.com/. Corrected script:

    var product = {
       "products_list":[
          {
             "category_id":"A",
             "product_details":[
                {
                   "product_id":"A.1",
                   "product_name":"AAAA1111",
                   "unit_cost":"A1"
                },
                {
                   "product_id":"A.2",
                   "product_name":"AAAA2222",
                   "unit_cost":"A2"
                },
                {
                   "product_id":"A.3",
                   "product_name":"AAAA3333",
                   "unit_cost":"A3"
                },
                {
                   "product_id":"A.4",
                   "product_name":"AAAA4444",
                   "unit_cost":"A4"
                },
                {
                   "product_id":"A.5",
                   "product_name":"AAAA5555",
                   "unit_cost":"A5"
                },
                {
                   "product_id":"A.6",
                   "product_name":"AAAA6666",
                   "unit_cost":"A6"
                },
                {
                   "product_id":"A.7",
                   "product_name":"AAAA7777",
                   "unit_cost":"A7"
                },
                {
                   "product_id":"A.8",
                   "product_name":"AAAA8888",
                   "unit_cost":"A8"
                },
                {
                   "product_id":"A.9",
                   "product_name":"AAAA9999",
                   "unit_cost":"A9"
                },
                {
                   "product_id":"A.0",
                   "product_name":"AAAA0000",
                   "unit_cost":"A0"
                }
             ]
          },
          {
             "category_id":"A",
             "product_details":[
                {
                   "product_id":"A.1",
                   "product_name":"AAAA1111",
                   "unit_cost":"A1"
                },
                {
                   "product_id":"A.2",
                   "product_name":"AAAA2222",
                   "unit_cost":"A2"
                },
                {
                   "product_id":"A.3",
                   "product_name":"AAAA3333",
                   "unit_cost":"A3"
                },
                {
                   "product_id":"A.4",
                   "product_name":"AAAA4444",
                   "unit_cost":"A4"
                },
                {
                   "product_id":"A.5",
                   "product_name":"AAAA5555",
                   "unit_cost":"A5"
                },
                {
                   "product_id":"A.6",
                   "product_name":"AAAA6666",
                   "unit_cost":"A6"
                },
                {
                   "product_id":"A.7",
                   "product_name":"AAAA7777",
                   "unit_cost":"A7"
                },
                {
                   "product_id":"A.8",
                   "product_name":"AAAA8888",
                   "unit_cost":"A8"
                },
                {
                   "product_id":"A.9",
                   "product_name":"AAAA9999",
                   "unit_cost":"A9"
                },
                {
                   "product_id":"A.0",
                   "product_name":"AAAA0000",
                   "unit_cost":"A0"
                }
             ]
          }
       ]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i m new to this android application development i would be very much grateful
I'm very much new to programming and have been doing fairly well so far.
I am new to javascript so sorry I don't know very much. I have
I am very new to sql.The actual problem is much bigger. I need information
i am very much new to Entity Framework and i just used this in
I am very much new to this word ESX. We recently decided to upgrade
I'm working on a small Java applet, very much new to this programming thing.
I am very much new to iOS. I am trying to create a customized
I have some json in this structure: {data:{1:file1.gif,2:file2.jpg}} // ... etc I am trying
Hei guys i have this JQuery Ajax call from my view and it looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.