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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:00:02+00:00 2026-05-31T06:00:02+00:00

I have a JSON array of objects, and am trying to work out how

  • 0

I have a JSON array of objects, and am trying to work out how to display them in Mustache.js. The array can be variable in length and content.

Example:

[ Object { id="1219", 0="1219", title="Lovely Book ", url= "myurl} , Object { id ="1220" , 0="1220 , title "Lovely Book2" , url="myurl2"}]

Ive tried:

        $.getJSON('http://myjsonurl?type=json', function(data) {
        var template = $('#personTpl').html();
        var html = Mustache.to_html(template, data);
        $('#test').html(html);

and the template:

 <script id="personTpl" type="text/template">
TITLE: {{#data}} {{title}} IMAGE: {{image}}
<p>LINK: <a href="{{blogURL}}">{{type}}</a></p>  {{/data}} 
</script>

but that doesn’t display anything.

I’ve tried putting the JSON into an array, and then accessing it directly using products[1] something like this:

$.getJSON("http://myjsonurl?type=json", function(json) 
{
    var products = [];

    $.each(json, function(i, product)
    {           
            var product =
            {           
                Title:product.title,
                Type:product.type,
                Image:product.image             
            };

            products.push(product);
        ;       
    });     

    var template = "<h1>Title: {{ Title }}</h1> Type: {{ Type }} Image : {{ Image }}";


    var html = Mustache.to_html(template, products[1]);
    $('#json').html(html);                      

}); 

which will display one record fine, but how can I iterate over them and display all ?

  • 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-31T06:00:04+00:00Added an answer on May 31, 2026 at 6:00 am

    You need a single JSON object that looks like:

    var json = { id:"1220" , 0:"1220", title:"Lovely Book2", url:"myurl2" };
    var template = $('#personTpl').html();
    var html = Mustache.to_html(template, json);
    $('#test').html(html);
    

    So something like this should work:

    $.getJSON('http://myjsonurl?type=json', function(data) {
    var template = $('#personTpl').html();
    $.each(data, function(key,val) {
    
            var html = Mustache.to_html(template, val);
            $('#test').append(html);
    });
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have an array of json objects like so: [{a:b},{c:d},{e:f}] What is the best
I'm trying to parse an array of JSON objects into an array of strings
Possible Duplicate: Length of Javascript Associative Array I have a JSON that looks like
I have an array of JSON objects, some of which contain key/value pairs for
Hi I have a JSON object that is a 2-dimentional array and I need
I have a JSON array like this: { forum:[ { id:1, created:2010-03-19 , updated:2010-03-19
I have a two dimensional JSON array where each element contains several attributes. The
Hi I want to create a JSON array. I have tried using: JSONArray jArray
I have a php file somejson.php that echos a json encoded array {jsonone:first json,jsontwo:second

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.