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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:45:46+00:00 2026-06-10T10:45:46+00:00

I’m new working with JSON and the getJSON function etc and I’m trying to

  • 0

I’m new working with JSON and the getJSON function etc and I’m trying to get data from a JSON that goes down several levels and can have multiple children. At the minute I can see the values I want by using .each with another .each such as:

$.each(data, function(i, value1) {
    $.each(value1, function(i, value2) {
        $.each(value2, function(i, value3) {
            $.each(value3, function(i, value4) {
                $.each(value4, function(i, value5) {
                    $.each(value5, function(i, value6) {
                        alert ("we got "+i);
                    });

The only problem is, I won’t always know what is in the JSON and it could have unlimited children. So how would I go about making it dynamic as such?

Basically what I’m looking for is something to keep checking for children until it gets to the lowest level.

Also, I know the value i at the very end is the index for whatever value is in the JSON,

Is there any way to automate this also so that I could check for say, ‘name’ in the JSON and it would return the value of ‘name’?

Here is a sample of the JSON i’m trying to work with:

[
 {
   "children": [
    {
      "children": [
       {
        "children": [
          {
            "children": [
              {
                "bucketPath": "AUDIO\\audio0.mp3",
                "id": 305,
                "modified": "2012-08-02T10:06:52",
                "name": "audio0.mp3",
                "state": "closed"
              }
  • 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-10T10:45:48+00:00Added an answer on June 10, 2026 at 10:45 am

    Use recursion:

    function recurse(name, obj) {
        if (!obj || typeof obj != "object")
            alert("found leaf '"+name+"': "+obj);
        else
            $.each(obj, recurse);
    }
    recurse("root", data);
    

    EDIT: Based on your JSON, one could make it more specific:

    function recurse(arr) {
       for (var i=0; i<arr.length; i++)
           for (var prop in arr[i])
               if (prop == "children") // && arr[i].children instanceof Array
                   recurse(arr[i].children);
               else
                   alert("we got "+prop+": "+arr[i][prop]);
    }
    recurse(data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.