I have a .txt file with following content.
[{"key": "HR", "value": "test@gmail.com"}, {"key": "Team Leader", "value": "test1@gmail.com"}, {"key": "PM", "value": "test3@gmail.com"}, {"key": "CEO", "value": "test4@gmail.com"}]
Now ,using php if i want to add another one value like
{“key”: “new_emailid”, “value”:”test5@gmail.com”}
The output should be lik this
[{"key": "HR", "value": "test@gmail.com"}, {"key": "Team Leader", "value": "test1@gmail.com"}, {"key": "PM", "value": "test3@gmail.com"}, {"key": "CEO", "value": "test4@gmail.com"}, {"key": "new_emailid", "value":"test5@gmail.com"}]
In other words, how to add content inside the square bracket of the exisiting .txt file. Is it possible to insert a content in between the brackets. Please help me
Thanks –
Haan
Since you are dealing with JSON the safest way would be to read the txt file and load it as JSON, add a new item, and save it back. Something like this: