Pretty Json


Given a string A representating json object. Return an array of string denoting json object with proper indentaion.

Rules for proper indentaion:

  • Every inner brace should increase one indentation to the following lines.
  • Every close brace should decrease one indentation to the same line and the following lines.
  • The indents can be increased with an additional ‘\t’

Note:

  1. [] and {} are only acceptable braces in this case.

  2. Assume for this problem that space characters can be done away with.



Input Format

The only argument given is the integer array A.

Output Format

Return a list of strings, where each entry corresponds to a single line. The strings should not have "\n" character in them.

For Example

Input 1:
    A = "{A:"B",C:{D:"E",F:{G:"H",I:"J"}}}"
Output 1:
    { 
        A:"B",
        C: 
        { 
            D:"E",
            F: 
            { 
                G:"H",
                I:"J"
            } 
        } 
    }

Input 2:
    A = ["foo", {"bar":["baz",null,1.0,2]}]
Output 2:
   [
        "foo", 
        {
            "bar":
            [
                "baz", 
                null, 
                1.0, 
                2
            ]
        }
    ]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Pretty Json on Interview Code Editor
Sign Up
to access hints and editorial solutions for Pretty Json
Asked In:

Discussion


Loading...
Click here to start solving coding interview questions