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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:41:53+00:00 2026-06-18T22:41:53+00:00

How to parse multilevel json ? Json format (n-level deep) : [ { attr

  • 0

How to parse multilevel json ?

Json format (n-level deep) :

    [
      {
        "attr" : {
        "id" : "97987"
      },
      "children" : [
            {
              "attr" : {
              "id" : "97988"
            },
            "children" : [
                  {
                    "attr" : {
                    "id" : "97992"
                  },
                  "data" : "tag5"
              }],
            "data" : "tag2"
        },
        {
          "attr" : {
              "id" : "97993"
          },
          "data" : "tag6"
        }
      ],
    "data" : "tag1"
  },
  {
    "attr" : {
        "id" : "97989",
    },
    "children" : [
          {
            "attr" : {
              "id" : "97990"
            },
            "data" : "tag4"
          }],
    "data" : "tag3"
  }
]

for eg. I want to read every children “id”.
I have tried $.each but that allows me to parse fixed number of levels.

  • 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-18T22:41:54+00:00Added an answer on June 18, 2026 at 10:41 pm

    You need to use recursion.

    function get_all_ids(data) {
        var result = [];
    
        $(data).each(function (i, element) {
            result.push(element.attr.id);
    
            if (element.children && element.children.length > 0) {
                var ids = get_all_ids(element.children);
    
                result = result.concat(ids); // or $.merge(result, ids);
            }
        });
    
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I parse data using JSON in javascript, I find this is very convenient. But
I would like to parse a self-designed file format with a FSM-like parser in
datetime parse work exactly when date format is like mm/dd/yyyy but when dateformat is
I parse an XML file to load data, and when i have an attribute
I would like to parse out any HTML data that is returned wrapped in
I am attempting to parse a string in Perl with the format: Messages pushed
I need to parse some scanned documents to textual data. Is it possible to
I parse data from /proc/[pid]/statm to get a clue about memory usage of a
I parse XML data and put it into an object. This takes fairly long
JSON.parse('abc'.to_json) gives this error (in rails): JSON::ParserError: 757: unexpected token at 'abc' from /Users/mpapper/.rvm/gems/ruby-1.9.2-p290@dfc-site/gems/json-1.7.4/lib/json/common.rb:155:in

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.