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

  • Home
  • SEARCH
  • 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 8827221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:19:20+00:00 2026-06-14T07:19:20+00:00

I’m writing a data viewer page to render objects being sent as JSON from

  • 0

I’m writing a data viewer page to render objects being sent as JSON from the server. The JSON objects vary in content and complexity, from flat objects with a handful of attributes, to larger structures with several layers of nesting and array fields. What I’d like to do is to render a simple representation of the object, probably as a ul. From there I can add stuff to allow clickable expand/collapse behaviour or something.

I know this will require a recursive function that I can call on the top level, which will then be called again for each level of nesting it discovers. I’m just not very confident with Javascript, and I’m not getting very far with it. I’m also having trouble with the fact that I don’t know the attribute names – different objects will have different attributes, with different names.

Is there a relatively simple way to render an object like this, or will I have to alter the form of the JSON that the server is sending?

EDIT:
Samples of the JSON probably won’t help much; they vary wildly. Like I said, some are simple, some are massively complex. The simplest objects are something like this:

{
    "id": "5",
    "category": "12",
    "created": "25-Sep-2012"
}

while the most complex one I have currently is something like this:

{
   "Attempted":"EditUser",
   "Exception":{
      "Message":"Something",
      "TargetSite":"somewhere",
      "Inner Exception":{
         "Message":"Something else",
         "TargetSite":"somewhere.core",
             "Inner Exception":{
            "Message":"Another message",
            "TargetSite":"something.core.subr",
            "Inner Exception":{
               "Message":"Object reference not set to an instance of an object.",
               "TargetSite":"System.Web.Mvc.ActionResult Update(Int32, System.String, System.String)",
               "StackTrace":[
                  "at Application.Controllers.AdminController.Update(Int32 id, String email, String password) in c:\\Docs\\Apps\\Main\\MyBranch\\Source\\Application\\Application\\Controllers\\AdminController.cs:line 123"
               ],
               "Inner Exception":{

               }
            }
         }
      }
   },
   "details":{
      "userEmail":"test@email.com",
      "userId":"25",
      "userRole":"User"
   }
}

As you can see, it’s a JSON representation of an error log, including the Exception thrown by the software (sensitive details have been obscured). The JSON objects are generated from the “detail” field of an audit log, so in future there may be other events logged whose details are in a different format to anything I predict now, which is why I’m looking to handle arbitrary JSON without reliance on knowing the format.

  • 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-14T07:19:21+00:00Added an answer on June 14, 2026 at 7:19 am

    You can use something like a BFS algorithm. Here’s an quick example (depends on jQuery):

    css

    ul {
        margin-left: 1em;
    }
    
    .json-key {
        font-weight: bold;
    }
    

    ​
    html

    <div id="json-viewer"></div>​
    

    javascript

    function visitObj($container, obj) {
        var $ul = $('<ul>');
    
        for (var prop in obj) {
    
            var $li = $('<li>');
            $li.append('<span class="json-key">' + prop + ': </span>');
            if (typeof obj[prop] === "object") {
                 visitObj($li, obj[prop]);
            } else {
                $li.append('<span class="json-value">'+obj[prop]+'</span>');                   
            }
            $ul.append($li);
        }
        $container.append($ul);
    }
    

    So calling this with your example:

    visitObj($('#json-viewer'), {
       "Attempted":"EditUser",
       "Exception":{
          "Message":"Something",
          "TargetSite":"somewhere",
          "Inner Exception":{
             "Message":"Something else",
             "TargetSite":"somewhere.core",
                 "Inner Exception":{
                "Message":"Another message",
                "TargetSite":"something.core.subr",
                "Inner Exception":{
                   "Message":"Object reference not set to an instance of an object.",
                   "TargetSite":"System.Web.Mvc.ActionResult Update(Int32, System.String, System.String)",
                   "StackTrace":[
                      "at Application.Controllers.AdminController.Update(Int32 id, String email, String password) in c:\\Docs\\Apps\\Main\\MyBranch\\Source\\Application\\Application\\Controllers\\AdminController.cs:line 123"
                   ],
                   "Inner Exception":{
    
                   }
                }
             }
          }
       },
       "details":{
          "userEmail":"test@email.com",
          "userId":"25",
          "userRole":"User"
       }
    });
    

    For a working example, see this fiddle.

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

Sidebar

Related Questions

I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
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
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.