Answer the question
In order to leave comments, you need to log in
How to generate a file from an array of data in JSON?
Good time.
I am looking for a script, framework or other solution for the task of converting data from json to files.
I give a simplified example:
There is a .json file of this kind
[
{
"name":"The Shawshank Redemption",
"year":"1994",
"stars":[
"Tim Robbins",
"Morgan Freeman",
"Bob Gunton"
]
},
{
"name":"The Godfather",
"year":"1972",
"stars":[
"Marlon Brando",
"Al Pacino",
"James Caan"
]
}
]
Answer the question
In order to leave comments, you need to log in
Lord, like that?
$data = json_encode($json);
foreach ($data as $movie) {
file_put_content('/path/to/dir'/ . $movie['name'] . '.txt', $movie['year'];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question