Reputation: 4432
How can I quick and easy save a JSON nested with php. What I mean with nested is this:
nested json:
{
"key1":"value",
"key2":"value",
"key3":"value",
"key4":{
"key1":"value",
"key2":"value",
"key3":"value"
},
"key5":{
"key1":"value",
"key2":"value",
"key3":"value"
}
}
json plain in one line(When I just use echo json_encode($array)):
{"key1":"value","key2":"value","key3":"value","key4":{"key1":"value","key2":"value","key3":"value"},"key5":{"key1":"value","key2":"value","key3":"value"}}
The reason I want this is that the json must be easy readable for humans. When everything is smacked on one line that doesn't help.
Upvotes: 0
Views: 144
Reputation: 5376
Using the right $options
parameter for json_encode
(PHP >= 5.4)
echo json_encode($object, JSON_PRETTY_PRINT);
Upvotes: 1