You might be interested in json_encode().

On the other hand if you already got something json encoded then it already is a string and you can simply store it as-is in the database.

Answer from VolkerK on Stack Overflow
🌐
PHP
php.net › manual › en › function.json-encode.php
PHP: json_encode - Manual
Returns a string containing the JSON representation of the supplied value. 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.
🌐
W3Schools
w3schools.com › js › js_json_php.asp
JSON PHP
Convert the object into a JSON string. Send a request to the PHP file, with the JSON string as a parameter.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-convert-a-string-to-json-object-in-php
How to Convert a String to JSON Object in PHP ? - GeeksforGeeks
July 23, 2025 - PHP provides convenient functions to work with JSON data. ... The json_decode() function is a versatile and commonly used method to convert a JSON-formatted string into a PHP object.
🌐
ReqBin
reqbin.com › code › php › ozcpn0mv › php-parse-json-example
How do I parse JSON string in PHP?
If the JSON cannot be parsed or ... with UTF-8 encoded strings. To encode PHP objects to JSON string, you can use json_encode($value) function....
🌐
Envato Tuts+
code.tutsplus.com › home › cloud & hosting
How to Parse JSON in PHP | Envato Tuts+
May 31, 2021 - However, once we convert it into ... turn your own data into a well-formatted JSON string in PHP with the help of the json_encode() function....
Find elsewhere
🌐
ReqBin
reqbin.com › code › php › 4qfsaffq › php-json-encode-example
How do I encode a PHP object to JSON string?
<?php $str = "Héllo, Wörld!"; echo json_encode($str, JSON_UNESCAPED_UNICODE); ?> #output: "Héllo, Wörld!" To decode a JSON string back into a PHP object, you can use the json_decode() function.
🌐
PHP
wiki.php.net › rfc › json_numeric_as_string
PHP: rfc:json_numeric_as_string
The first option called JSON_FLOAT_AS_STRING converts all float values to string.
🌐
JD Bots
jd-bots.com › 2023 › 02 › 14 › convert-json-to-string-in-php-quick-guide
Convert JSON to String in PHP: Quick Guide
February 14, 2023 - To convert a JSON object to a string in PHP, you can use the json_encode function.
🌐
Scout APM
scoutapm.com › blog › php-json-encode-serialize-php-objects-to-json
PHP Json_encode: Serialize PHP Objects to JSON
The function takes in a PHP object ($value) and returns a JSON string (or False if the operation fails). Don’t worry about the $options and $depth parameters; you’re seldom going to need them.
🌐
SitePoint
sitepoint.com › php
Encoding/Decoding JSON PHP - PHP - SitePoint Forums | Web Development & Design Community
February 19, 2023 - This is sent to my PHP file so I can’t just type out $myData = ‘[{"key":"value"},{"key":"value"}]’ like many of the string examples I have found online. I know this is the syntax because I can save it straight to the database as a whole but I can’t figure out how to extract the keys and values individually. I can do this with Javascript, so needing to be schooled in PHP on how to do this. Please help. ... Just replace the backslash double quotes by double quotes and decode it. $data = json_decode(str_replace(‘\"’, ‘"’, $source));
🌐
W3Docs
w3docs.com › php
How to convert a string to JSON object in PHP
<?php $json = '{"name":"John", "age":30, "city":"New York"}'; // decode the JSON data into a PHP object $obj = json_decode($json); // access the object properties echo $obj->name . PHP_EOL; // John echo $obj->age . PHP_EOL; // 30 echo $obj->city; // New York ... You can also pass a second argument to json_decode to convert the JSON string into an associative array:
🌐
Plus2Net
plus2net.com › php_tutorial › json_encode.php
json_encode PHP function to create Json string to exchange data
Json is a data exchange format like XML. You can learn about Json support of PHP here. json_encode function takes data and converts them to a string, we call it as Json string.
Top answer
1 of 6
175

What @deceze said is correct, it seems that your JSON is malformed, try this:

{
    "Coords": [{
        "Accuracy": "30",
        "Latitude": "53.2778273",
        "Longitude": "-9.0121648",
        "Timestamp": "Fri Jun 28 2013 11:43:57 GMT+0100 (IST)"
    }, {
        "Accuracy": "30",
        "Latitude": "53.2778273",
        "Longitude": "-9.0121648",
        "Timestamp": "Fri Jun 28 2013 11:43:57 GMT+0100 (IST)"
    }, {
        "Accuracy": "30",
        "Latitude": "53.2778273",
        "Longitude": "-9.0121648",
        "Timestamp": "Fri Jun 28 2013 11:43:57 GMT+0100 (IST)"
    }, {
        "Accuracy": "30",
        "Latitude": "53.2778339",
        "Longitude": "-9.0121466",
        "Timestamp": "Fri Jun 28 2013 11:45:54 GMT+0100 (IST)"
    }, {
        "Accuracy": "30",
        "Latitude": "53.2778159",
        "Longitude": "-9.0121201",
        "Timestamp": "Fri Jun 28 2013 11:45:58 GMT+0100 (IST)"
    }]
}

Use json_decode to convert String into Object (stdClass) or array: http://php.net/manual/en/function.json-decode.php

[edited]

I did not understand what do you mean by "an official JSON object", but suppose you want to add content to json via PHP and then converts it right back to JSON?

assuming you have the following variable:

$data = '{"Coords":[{"Accuracy":"65","Latitude":"53.277720488429026","Longitude":"-9.012038778269686","Timestamp":"Fri Jul 05 2013 11:59:34 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.277720488429026","Longitude":"-9.012038778269686","Timestamp":"Fri Jul 05 2013 11:59:34 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.27770755361785","Longitude":"-9.011979642121824","Timestamp":"Fri Jul 05 2013 12:02:09 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.27769091555766","Longitude":"-9.012051410095722","Timestamp":"Fri Jul 05 2013 12:02:17 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.27769091555766","Longitude":"-9.012051410095722","Timestamp":"Fri Jul 05 2013 12:02:17 GMT+0100 (IST)"}]}';

You should convert it to Object (stdClass):

$manage = json_decode($data);

But working with stdClass is more complicated than PHP-Array, then try this (use second param with true):

$manage = json_decode($data, true);

This way you can use array functions: http://php.net/manual/en/function.array.php

adding an item:

$manage = json_decode($data, true);

echo 'Before: <br>';
print_r($manage);

$manage['Coords'][] = Array(
    'Accuracy' => '90'
    'Latitude' => '53.277720488429026'
    'Longitude' => '-9.012038778269686'
    'Timestamp' => 'Fri Jul 05 2013 11:59:34 GMT+0100 (IST)'
);

echo '<br>After: <br>';
print_r($manage);

remove first item:

$manage = json_decode($data, true);
echo 'Before: <br>';
print_r($manage);
array_shift($manage['Coords']);
echo '<br>After: <br>';
print_r($manage);

any chance you want to save to json to a database or a file:

$data = '{"Coords":[{"Accuracy":"65","Latitude":"53.277720488429026","Longitude":"-9.012038778269686","Timestamp":"Fri Jul 05 2013 11:59:34 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.277720488429026","Longitude":"-9.012038778269686","Timestamp":"Fri Jul 05 2013 11:59:34 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.27770755361785","Longitude":"-9.011979642121824","Timestamp":"Fri Jul 05 2013 12:02:09 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.27769091555766","Longitude":"-9.012051410095722","Timestamp":"Fri Jul 05 2013 12:02:17 GMT+0100 (IST)"},{"Accuracy":"65","Latitude":"53.27769091555766","Longitude":"-9.012051410095722","Timestamp":"Fri Jul 05 2013 12:02:17 GMT+0100 (IST)"}]}';

$manage = json_decode($data, true);

$manage['Coords'][] = Array(
    'Accuracy' => '90'
    'Latitude' => '53.277720488429026'
    'Longitude' => '-9.012038778269686'
    'Timestamp' => 'Fri Jul 05 2013 11:59:34 GMT+0100 (IST)'
);

if (($id = fopen('datafile.txt', 'wb'))) {
    fwrite($id, json_encode($manage));
    fclose($id);
}
2 of 6
30

To convert a valid JSON string back, you can use the json_decode() method.

To convert it back to an object use this method:

$jObj = json_decode($jsonString);

And to convert it to a associative array, set the second parameter to true:

$jArr = json_decode($jsonString, true);

By the way to convert your mentioned string back to either of those, you should have a valid JSON string. To achieve it, you should do the following:

  1. In the Coords array, remove the two " (double quote marks) from the start and end of the object.
  2. The objects in an array are comma seprated (,), so add commas between the objects in the Coords array..

And you will have a valid JSON String..

Here is your JSON String I converted to a valid one: http://pastebin.com/R16NVerw

🌐
ReqBin
reqbin.com › code › php › 0uwqq41y › json-to-array-php-example
How do I convert JSON to PHP array?
Many programming languages have built-in or external libraries for creating and manipulating JSON data strings, including JavaScript, Python, C++, C#, Go, PHP, and Java. You can use the json_decode() function to convert JSON strings into PHP objects.
🌐
Tutorial Republic
tutorialrepublic.com › php-tutorial › php-json-parsing.php
How to Encode and Decode JSON Data in PHP - Tutorial Republic
In PHP the json_encode() function is used to encode a value to JSON format. The value being encoded can be any PHP data type except a resource, like a database or file handle.
🌐
DevDungeon
devdungeon.com › content › working-json-php
Working with JSON in PHP | DevDungeon
August 5, 2020 - If you have a PHP object like an array and you need to "export" the value as a string, you can use json_encode().