I am getting a nested json object back from an api call and I am trying to save it to a newline delimited json file so it can be imported into Google Big Query.
Here is what I have and it saves it to my file but still not correctly formatted for Big Query to import it.
$response = $this->client->post($url);
$results = json_decode($response->getBody()->getContents());
$date = Carbon::now()->toDateString();
$filename = 'resources/results-' . $date . '.ndjson';
foreach ($results as $result) {
$newline = json_encode($result) . "\n";
file_put_contents(base_path($filename), $newline, FILE_APPEND);
}
I have also just tried to save the json to a file but get same error when trying to import to big query.