How to use PHP to add data to a specified object in an JSON document

want to know how to add
to the specified object in the document
eg:

after generating a set of json and adding it to the specified sncode.json using file_put_contents.
{"sncode":[
    {"model":"666","sncode":"2333333"},
    {"model":"666","sncode":"1234569"},
    {...}
]}

at present, when I add a new json, it will only be

all the time.
    {"model":"666","sncode":"2333333"},{"model":"666","sncode":"1234569"}    
    {"model":"666","sncode":"1234569"}{"model":"666","sncode":"1234569"}

because the format of json is out of order from the second one, I can"t read the JSON information correctly anyway.

Mar.07,2021

read, decode, add, encode, write


read: $cont = file_get_content ($file);
Decoding: $info = json_decode ($cont, true);
add: $info ['sncode'] [] = [' model'= > '66613'];
Encoding: $json = json_encode ($info);
write: file_put_content ($json);

)
Menu