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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:30:02+00:00 2026-06-12T08:30:02+00:00

I am trying to convert a JSON into an unordered list in jQuery.This is

  • 0

I am trying to convert a JSON into an unordered list in jQuery.This is my JSON data.

var myJSON = "{name:\"Director\",children:[name:\"Exe Director1\",name:\"Exe Director2\",name:\"Exe Director3\",children:[name:\"Sub Director1\",name:\"Sub Director2\",name:\"Sub Director3\",children:[name:\"Cameraman 1\",name:\"Cameraman 2\"]]]}";

The expected output being

<ul>
    <li>Director
        <ul>
            <li>Exe Director 1</li>
            <li>Exe Director 2</li>
            <li>Exe Director 3
                <ul>
                    <li>Sub Director 1</li>
                    <li>Sub Director 2</li>
                    <li>Sub Director 3
                        <ul>
                            <li>Cameraman 1</li>
                            <li>Cameraman 2</li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
    </li>
</ul>

How do I go about with this!

Cheers,

  • 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-12T08:30:04+00:00Added an answer on June 12, 2026 at 8:30 am

    This is exactly what you need:

    Use the jQuery template API. This was once part of jQuery but is currently only available as plugin. However, I think jQuery will adopt this or a similar technique again soon.

    http://api.jquery.com/category/plugins/templates/

    Its super easy to use:

    $.tmpl("template", jsonObject)
    

    Here a small basic template example:

    $.tmpl(
        "<li><b>${Id}</b>${Name}</li>", 
        [{Id:1, Name:"Werner"}, {Id:2, Name:"Klaus"}]
    );
    

    This will result in the following jQuery HTML element that can be appended to anywhere:

  2. 1 Werner
  3. 2 Klaus
  4. For your complex data, you can also iterate JSON sub objects using the “{{each}}” template notation. Here the code for your data and template:

    var data = {name:"Director",children:[{name:"Exe Director1"},{name:"Exe Director2"},{name:"Exe Director3", children:[{name:"Sub Director3_1"},{name:"Sub Director3_2"},{name:"Sub Director3_3",children:[{name:"Cameraman3_3_1"},{name:"Cameraman3_3_2"}]}]}]};
    
    var template = '\
        <ul>\
            <li>${name}\
                <ul>\
                    {{each(childindex, child) children}}\
                        <li>${child.name}\
                            <ul>\
                                {{each(child2index, child2) child.children}}\
                                    <li>${child2.name}</li>\
                                {{/each}}\
                            </ul>\
                        </li>\
                    {{/each}}\
                </ul>\
            </li>\
        </ul>\
    ';
    
    $('body').empty().append($.tmpl(template, data));
    

    Browsers Result:

    • Director
      • Exe Director1
      • Exe Director2
      • Exe Director3
        • Sub Director3_1
        • Sub Director3_2
        • Sub Director3_3
        • …

    This can be tweaked to support full recursion by including nested templates… but im a lazy guy and the rest is todo for you.

    cheers,
    will

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

Sidebar

Related Questions

I am trying to convert a mySQL query into a JSON object. This works:
I'm trying to write a function to convert a python list into a JSON
I am trying to convert some xml into a json object using PHP. This
I'm trying to use Jackson to convert some JSON data into Java objects ,a
I'm trying to use gson to convert this returned JSON into some kind of
I'm new to JSON and trying this tutorial: http://p-xr.com/android-tutorial-how-to-parse-read-json-data-into-a-android-listview/#comments I'm new to JSON, C
I am querying a database for results and trying to convert them into JSON
I am using the JQuery json plugin and trying to convert a custom object
I am trying to convert an object into JSON using the GSON library on
I'm trying to convert a parsed JSON document in a lift-json's JValue into a

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.