How to show json into client like this link
            Asked
            
        
        
            Active
            
        
            Viewed 84 times
        
    -4
            
            
        - 
                    2`json_encode` returns a JSON string - just echo that. Is there some other detail I'm missing? – Sampson Dec 24 '12 at 16:05
- 
                    What exactly do yo mean? – Sverri M. Olsen Dec 24 '12 at 16:06
- 
                    do you mean to output json string in a formatted way? – ianace Dec 24 '12 at 16:10
- 
                    while i use json_encode, the browser shows a string, and the format is only one line, not like the link. i am confused... – jiemoon Dec 24 '12 at 16:13
2 Answers
0
            
            
        I believe you are talking about indentation, right? If you are, you should notice that this json output is surrounded by a <pre> tag and it's filled with blank spaces to separate the pieces of data:
{     "data": [         {             "canonical_url": "https://alpha.app.net/marcozehe/post/2172854",
Did you try to replicate that? You can also check this other question: Javascript: How to generate formatted easy-to-read JSON straight from an object?
just checking: you are not talking about the REST-like URL, are you?
 
    
    
        Community
        
- 1
- 1
 
    
    
        the_marcelo_r
        
- 1,847
- 22
- 35
0
            Use the JSON_PRETTY_PRINT option:
$data = Array( 
    "Foo" => "Bar",
    "Fiz" => "Buz"
);
echo json_encode($data, JSON_PRETTY_PRINT);
This requires PHP 5.4.0 or greater. The output follows:
{
    "Foo": "Bar",
    "Fiz": "Buz"
}
 
    
    
        Sampson
        
- 265,109
- 74
- 539
- 565
