fork(3) download
  1. <?php
  2.  
  3. $s = <<<JSON
  4. {
  5.   "books":[
  6.   {
  7.   "email":"test@test.te",
  8.   "author":"John Name",
  9.   "created":"2017-03-24 10:41:21"
  10.   },
  11.   {
  12.   "email":"test@test.te",
  13.   "author":"John Name",
  14.   "created":"2017-03-24 10:41:21"
  15.   },
  16.   {
  17.   "email":"test@test.te",
  18.   "author":"John Name",
  19.   "created":"2017-03-24 10:41:21"
  20.   }
  21.   ]
  22. }
  23. JSON;
  24.  
  25. $json = json_decode($s, true);
  26.  
  27. $json['books'][] = [
  28. 'email' => 'foo',
  29. 'author' => 'bar',
  30. 'created' => '42',
  31. ];
  32.  
  33. var_dump(json_encode($json, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE));
  34.  
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
string(543) "{
    "books": [
        {
            "email": "test@test.te",
            "author": "John Name",
            "created": "2017-03-24 10:41:21"
        },
        {
            "email": "test@test.te",
            "author": "John Name",
            "created": "2017-03-24 10:41:21"
        },
        {
            "email": "test@test.te",
            "author": "John Name",
            "created": "2017-03-24 10:41:21"
        },
        {
            "email": "foo",
            "author": "bar",
            "created": "42"
        }
    ]
}"