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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:24:50+00:00 2026-06-01T12:24:50+00:00

I copied this from the jquery site. I’m trying to learn how to get

  • 0

I copied this from the jquery site. I’m trying to learn how to get json data to a web page. The date has validated on: http://jsonlint.com/

The results from running the my script are:
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]

Do I need to parse the data or does getJSON do that.
This is the code I’m using:

<!doctype html> 
<html>
<head>

    <script type="text/javascript" src="js/jquery-1.7.1.js"></script>

    <script type="text/javascript">
$.getJSON('data.json', function(data) {
  var items = [];

  $.each(data, function(key, val) {
    items.push('<li id="' + key + '">' + val + '</li>');
  });

  $('<ul/>', {
    'class': 'my-new-list',
    html: items.join('')
  }).appendTo('body');
});
    </script>
</head>
<body>

</body>
</html>

Troubleshooting tips would be great and of course an answer would be great too!

data.json

[
    {
        "bytes": "476.577044"
    },
    {
        "bytes": "136113.5289"
    },
    {
        "bytes": "118870.8151"
    },
    {
        "bytes": "55001.67852"
    }
]

console.log(data) response:

[Object { bytes="476.577044"}, Object { bytes="136113.5289"}, Object { bytes="118870.8151"}, Object { bytes="55001.67852"}]
JSON.html (line 14)
[Object { bytes="476.577044"}, Object { bytes="136113.5289"}, Object { bytes="118870.8151"}, Object { bytes="55001.67852"}]
JSON.html (line 14)
[Object { bytes="476.577044"}, Object { bytes="136113.5289"}, Object { bytes="118870.8151"}, Object { bytes="55001.67852"}]
JSON.html (line 14)
[Object { bytes="476.577044"}, Object { bytes="136113.5289"}, Object { bytes="118870.8151"}, Object { bytes="55001.67852"}]
  • 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-01T12:24:51+00:00Added an answer on June 1, 2026 at 12:24 pm

    Pretty close, try this: (as long as the file “data.json” is a valid file)

    $(document).ready(function(){
        $.getJSON('data.json', function(data) {
          var items = [];
    
          $.each(data, function(key, val) {
            items.push('<li id="' + key + '">' + val + '</li>');
          });
    
          $('<ul/>').addClass('my-new-list').html(items.join('')).appendTo('body');
        });
    });
    

    EDIT

    The way your json is setup, $.each is going to iterate the outer array containing the objects. Which makes the key a numeric index, and the val the actual object. With that said, changing the $.each part to look like this:

    $.each(data, function(key, val) {
        items.push('<li id="' + key + '">' + val.bytes + '</li>');
    });
    

    should do the trick

    (sidenote: id’s should not begin with a number)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to get this really simple example of using AJAX with JQuery
I copied this example from api.jquery.com $('.target').change(function() { alert('Handler for .change() called.'); }); I
I'm trying the slider widget in jQuery Mobile, and just copied the code from
I copied this code from an example . I've read it 100 times. Array.prototype.map
this is copied from http://www.zenspider.com/ZSS/Products/RubyInline/Readme.html , the home of rubyinline, adding/moding as indicated in
I have this sample code for async operations (copied from the interwebs) public class
I copied and pasted this binary data out of sql server, which I am
I made an example , I copied it straight from the jQuery website yet,
I'm using jquery validation, however a few particular field values can be copied from
I've copied some text nodes from the page (i.e., live DOM) and have stored

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.