I have a JSON file with a JSON object I am attempting to read and edit using PHP but I wanted to change specific Key values which is proving to be abit of a problem. Would anyone have any pointers or links they may know that may help?
Thanks
You can try this.
Firstly, decode your JSON:
$json_object = file_get_contents('some_file_name.json');
$data = json_decode($json_object, true);
Then edit what you want such as:
$data['some_key'] = "some_value";
Finally rewrite it back on the file (or a newer one):
$json_object = json_encode($data);
file_put_contents('some_file_name.json', $json_object);
Note: I assumed that the JSON comes from a file, but in place of that file system function you can very well use anything that returns a JSON object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With