简体   繁体   中英

How to save a nested json in txt file with php

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.

json_encode使用正确的$options参数(PHP> = 5.4)

echo json_encode($object, JSON_PRETTY_PRINT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM