There is no thing like a "json array" or "json object". JSON is always text. It is a text representation of a data structure that can be an array or an object. It uses the JavaScript notation for arrays and objects.
In order to get this JSON:
"History":{
0:{
name: "some text"
},
1:{
name: "some text 2"
}
}
you need to build a PHP object or array. PHP arrays are more versatile than bare objects and I recommend you use them.
PHP arrays whose keys are numeric, consecutive and starting from zero are
encoded as arrays in JSON. The other arrays are encoded as objects.
This array must have only one key ("History"
) and its associated value must be an array (numerically indexed) that contains two arrays. Each of these arrays must have only one key: "name"
.
Your array would be like this:
$input = array(
"History" => array(
array("name" => "some text"),
array("name" => "some text 2"),
),
);
When passed to json_encode()
it produces a JSON equivalent to the one you expect.
There are countless ways to build the input array. Read more about accessing and modifying array elements using the square brackets syntax.