0

i have a data.json file that looks like this:

{"price_usd":[
  ["June 3, 2022",886.754],
  ["June 5, 2022",899.644],
  ["June 6, 2022",891.014],
  ["June 7, 2022",13685.4],
  ["June 8, 2022",13411]
]
}

I want to add another date + price to this data.json file (inside the price_usd, after june 8), but i dont really know how to do this. Ive looked up different documentations, but all of them had different way to how they formed their JSON. I cannot use another format, since its connected to a graph.

This is what i have (php), but it just wipes the data.json:

$file=fopen("data.json","w");

$array_data=array();
$extra = array("June 10, 2022", 455);
$array_data["price_usd"] = $extra;
$final_data = json_encode($array_data);
fclose($file);
return $final_data;

Eeplo
  • 15
  • 4
  • Read the file, use `json_decode()` to parse it. Add the new item to the array. Then save it. – Barmar Jun 03 '22 at 15:58

0 Answers0