-4

How to show json into client like this link

https://alpha-api.app.net/stream/0/posts/stream/global

jiemoon
  • 5
  • 2

2 Answers2

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