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 6662301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:22:31+00:00 2026-05-26T02:22:31+00:00

I am trying to print out a list of JSON object attributes. I also

  • 0

I am trying to print out a list of JSON object attributes. I also tried to print out an individual ob object’s attribute. The printout to the console indicates that I am opening the file and receiving the two objects and sub objects okay. However, I am making a mistake somewhere in trying to cycle through the objects and print them out an attribute of each.

...
<script type="text/javascript">
    var dta1;
    $(document).ready(function() {
        $.ajax({
            type : "GET",
            url : "data/data5.json",
            success : function test(data) {
                dta1 = data.object1;
                dta2 = data.object2;

                console.log("object1", dta1);               
                console.log("object2", dta2);               
            }
        });
    });
</script>

</head>
<body>
    <script type="text/javascript">
        for(i in dta1){
            document.write(dta1[i].x);
        }
        document.write(dta1["object11"].x);
    </script>
</body>

Here’s the json file.

{
    "object1": {
        "object11": {"x": "10", "y": "20", "z": "30"}, 
        "object12": {"x": "40", "y": "50", "z": "60"}, 
        "object13": {"x": "70", "y": "80", "z": "90"}
    }, 
    "object2": {
        "object21": {"x": "100", "y": "200", "z": "300"}, 
        "object22": {"x": "400", "y": "500", "z": "600"}, 
        "object23": {"x": "700", "y": "800", "z": "900"}
    }
}
  • 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-05-26T02:22:31+00:00Added an answer on May 26, 2026 at 2:22 am

    Your second script block will run before the one in the head due to your use of the jQuery “document ready” handler which only runs after the document has fully loaded.

    Also, you can’t rely on an asynchronous request (AJAX) completing before your next block of code runs. Anything that uses data retrieved via AJAX should be called within the “success” callback.

    What you should probably do is create a container element in your HTML, eg

    <body>
        <ul id="data-container"></ul>
    </body>
    

    and append the values to that within your AJAX success callback, eg

    success : function test(data) {
        var dta1 = data.object1;
        var dta2 = data.object2;
    
        var container = $("#data-container");
    
        for (var o in dta1) {
            if (dta1.hasOwnProperty(o)) {
                container.append($("<li>").text(dta1[o].x));
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to print out a list of products on a page. This is
I'm trying to come up with an algorithm that will print out all possible
I'm trying to print out a list of names and i want to be
I was trying to print out a list of symbols and I was wondering
Here's what I am trying to do: Given a list of names, print out
I'm trying to reverse a linked list by using C++ and then print out
I am trying to use a report to print out a list of users
I'm trying to print out a list of the change list numbers (and optionally
I'm trying to print out a list of strings thus: std::list<String> const &prms =
I'm trying to print out just the non-empty strings in a list. I can't

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.