2

as I can modify a json in laravel file? In the methods available for the File class, only allows me to add additional text:

File::append($path, $data);

however, can not find a method to modify.

example:

public function json(){
      $data = json_encode([
         'data1' => 'hello',
          'data2' => 'world' ]);
  File::append($path, $data);
}

public function ModifyJson(){

//how change value for data2?  

}

thank you very much for the help :)

1
  • 1
    file_get_contents(), then json_decode(), then modify, then file_put_contents() Commented Aug 2, 2016 at 20:46

1 Answer 1

3

Use $data = json_decode($your_file_content,true), then modify $data as normal php array, and before save use json_encode($data) and save data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.