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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:53:24+00:00 2026-06-13T08:53:24+00:00

How to output an object as a readable string with formatting (structured like with

  • 0

How to output an object as a readable string with formatting (structured like with <pre>) ?

No jQuery possible.

My object looks like this using console.log.

Object
   title: "Another sting"
   type: "tree"
   options: Object
      paging: "20"
      structuretype: "1"
   columns: Object
      ...
   description: "This is a string"
   ...

What is the best to convert it to a structured string?

My attempt:

I tried using stringify() to get the JSON structure. I could then write my own parser, but maybe there are already any implementations?

  • 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-13T08:53:25+00:00Added an answer on June 13, 2026 at 8:53 am

    JSON.stringify includes a formatting argument:

    JSON.stringify(value[, replacer [, space]])

    The space argument may be used to control spacing in the final string. If it is a number, successive levels in the stringification will each be indented by this many space characters (up to 10). If it is a string, successive levels will indented by this string (or the first ten characters of it).

    Using a tab character mimics standard pretty-print appearance

    https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify

    Is that enough formatting for what you need? E.g. try:

     JSON.stringify( object, null, 2 );
    

    Otherwise, http://code.google.com/p/google-code-prettify/ is a standalone JSON to HTML pretty printer. Used by stackoverflow and google code, I believe.

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

Sidebar

Related Questions

I'm using console.log(data.result) to discover an object hierarchy, here's the output: [ Object delete_type:
When I console.log() an object in my JavaScript program, I just see the output
I use object buffering to buffer the output of my php pages using ob_start('ob_gzhandler');
Output in Log: ibtoold(1642,0x7fff78b64960) malloc: error for object 0x7fbf38056a08: incorrect checksum for freed object
There is this output of objdump on some object file: $ objdump -h main.o
in what way can I output the reference of an object in memory. Like:
Possible Duplicate: passing in object by ref With the code below, the output would
In Nodejs, when I console.log a req object, what does [Circular] mean? Here's an
I wish to convert a Color Object into a human readable String. To clarify
I am using JSON.parse to parse this JSON string [{created_at:2012-01-24T22:36:21Z,name:joe,age:42,updated_at:2012-01-24T22:36:21Z}] However I am simply

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.