Replace "[with [and]" with] json

I have JSON as shown below:

[{"type":"Point","coordinates":"[-77.03,38.90]"},"properties":{"city":3,"url":"xyz.com"}]

I want to replace "[with [and ]"by]

+4
source share
3 answers

try it

 $yourJson = [{"type":"Point","coordinates":"[-77.03,38.90]"},"properties":{"city":3,"url":"xyz.com"}];
 $jsonString=preg_replace('/"([^"]+)"\s*:\s*/', '$1:', $yourJson);
    $stringReplace=str_replace('"[', '[', $jsonString);
    $stringReplace=str_replace(']"', ']', $stringReplace);
    echo $stringReplace;
+3
source

from the comment it seems that you add an extra quote "instead

json = json.replace("\"[","[");
0
source

:

str.replace(/"(\[[^"\]]*\])"/, "$1");

str - . "[, , " ], ]" " . "[-77.03,38.90]" [-77.03,38.90].

, , , .

0

Source: https://habr.com/ru/post/1527288/


All Articles