Just decode your json string and then use array push

$tempArray = json_decode($jsonstring, true);
array_push($tempArray, $your_data);

For your case

    $str = '{ 

"players":[
   {

        "name":"Moldova",
        "image":"/Images/Moldova.jpg",
        "roll_over_image":"tank.jpg"
   },
   {

        "name":"Georgia",
        "image":"/Images/georgia.gif",
        "roll_over_image":"tank.jpg"
   } ]}';


 $arr = json_decode($str, true);
 $arrne['name'] = "dsds";
 array_push( $arr['players'], $arrne );
 print_r($arr);

Just check value of print_r($arr); I hope this is what you want. :)

Answer from chandresh_cool on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-create-an-array-for-json-using-php
How to create an array for JSON using PHP? - GeeksforGeeks
July 11, 2025 - These keys will be a string or an integer which will be used as an index to search the corresponding value in the array. The json_encode() function is used to convert the value of the array into JSON. This function is added in from PHP5.
🌐
Tek-Tips
tek-tips.com › home › forums › software › programmers › web development › php
Add an new JSON array into an existing JSON array 2 - PHP
April 18, 2019 - Besides, you can always extend an array by assigning to a non named element, which means "append at the end as a new element": ... $arr1[]=$arr2 Since you want $arr2 as a new row in $arr1 and rows in $arr1 consist of an array each, that's wanting to add $arr2 as new element and this code does ...
🌐
W3Schools
w3schools.com › php › php_json.asp
PHP and JSON
PHP has some built-in functions to handle JSON. First, we will look at the following two functions: ... The json_encode() function is used to encode a value to JSON format. This example shows how to encode an associative array into a JSON object:
🌐
IBM
ibm.com › docs › en › integration-bus › 9.0.0
Using PHP arrays with JSON
July 21, 2017 - We cannot provide a description for this page right now
Top answer
1 of 4
9
$data = json_decode($file, true);
//When TRUE, returned objects will be converted into associative arrays.
unset($file);

$newImage = array('image' => $link, 'folder' => $category);
//$newImage['image'] = $link;
//$newImage['folder'] = $category;
$result = array_merge($data, $newImage);
//don't need to cast

Reference PHP json_decode Manual

Edit The following code works (tested)

function addToJsonImageList($link, $category) {
    $file = file_get_contents('./images_list.json', true);
    $data = json_decode($file,true);
    unset($file);
    //you need to add new data as next index of data.
    $data[] = array('image' => $link, 'folder' => $category);
    $result=json_encode($data);
    file_put_contents('./images_list.json', $result);
    unset($result);
}

Edit 2 added lot of error reporting and debugging. Please let me know the output of the following. The code below is not tested (just typed in here).please fix if you find any syntax error. it is late here and can only check tomorrow my time, but can reply.

<?php
//display all errors and warnings
error_reporting(-1);
addToJsonImageList('test link', 'test category');

function addToJsonImageList($link, $category) {
    $file = file_get_contents('./images_list.json', true);
    if ($file===false)die('unable to read file');
    $data = json_decode($file,true);
    if ($data ===NULL)die('Unable to decode');
    unset($file);
    echo "data before\n";
    var_dump ($data);
    //you need to add new data as next index of data.
    $data[] = array('image' => $link, 'folder' => $category);
    echo "data after\n";
    var_dump ($data);
    $result=json_encode($data);
    if (file_put_contents('./images_list.json', $result) === false){
        die('unable to write file');
    }
    unset($result);
}
?>
2 of 4
1

Lets say you have this .json file named (playerJson)

{

"Players":
   [
     {"Name":"Arun","Arm":"Gun","num":"1"},
     {"Name":"sssv","Arm":"Arc","num":"2"},
     {"Name":"Surya","Arm":"Bomb","num":"3"},
     {"Name":"sssv","Arm":"Fire","num":"4"}

   ]
}

Now what we have to do in php (myPhpFile.php) is : (I suppose you are loading your data from a form)

<?php

$json = file_get_contents('playerJson.json');
$json_data = json_decode($json,true);

$newar = array(
           'Name'=>$_POST['nameField'] ,
           'Arm' =>$_POST['armField'],
           'Num' =>$_POST['numField']
);
//saving data in Players object...
array_push($json_data['Players'], $newar);

$json = json_encode($json_data);

file_put_contents('playerJson.json', $json);

?>

That's all ! You have a new line in your "Players" Object. But if you want to add a new object, avoid the [Players] after $json_data in the array_push function.

🌐
PHP
php.net › manual › en › function.json-encode.php
PHP: json_encode - Manual
If the parameter is an array or object, it will be serialized recursively. If a value to be serialized is an object, then by default only publicly visible properties will be included. Alternatively, a class may implement JsonSerializable to control how its values are serialized to JSON. The encoding is affected by the supplied flags and additionally ...
🌐
W3Schools
w3schools.com › js › js_json_php.asp
JSON PHP
Convert the request into an object, using the PHP function json_decode(). Access the database, and fill an array with the requested data. Add the array to an object, and return the object as JSON using the json_encode() function.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 53480956 › add-object-to-specific-json-php-array
Add Object to Specific json PHP array
I have been looking for a while how to add this two objects to inside DATA of my json call. ... $signer = array( 'signatures' => array('some data'), 'pubkeys' => array('some data'), ); array_push($result, $signer);
🌐
C# Corner
c-sharpcorner.com › article › write-and-append-data-in-json-file-using-php
Write And Append Data In JSON File Using PHP
December 3, 2021 - if(file_exists('file.json')) { $final_data=fileWriteAppend(); if(file_put_contents('file.json', $final_data)) { $message = "<label class='text-success'>Data added Success fully</p>"; } } else { $final_data=fileCreateWrite(); if(file_put_contents('file.json', $final_data)) { $message = "<label class='text-success'>File createed and data added Success fully</p>"; } } function fileWriteAppend(){ $current_data = file_get_contents('file.json'); $array_data = json_decode($current_data, true); $extra = array( 'name' => $_POST['name'], 'gender' => $_POST["gender"], 'age' => $_POST["age"], 'education'
🌐
Quora
quora.com › How-do-I-make-a-JSON-array-in-PHP
How to make a JSON array in PHP - Quora
How can I convert it to PHP/array/JSON? ... If you want to know how many beers there are, use count($json->data). ... If you want to know how many beers there are, use count($json->data). ... Project Engineer at Technoplanet Lab Pvt Ltd (2018–present) · Author has 138 answers and 263K answer views · Updated 5y ... Array elements are represented by index or numbers. It can store any type of data ,eg:numbers, strings, objects...
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-append-data-in-json-file-through-html-form-using-php
How to append data in JSON file through HTML form using PHP ? - GeeksforGeeks
July 15, 2025 - To send data from HTML form to JSON file we are using json_encode() function which returns a JSON encoded string. We are making an array of values that the user fills in the HTML form.