Created
October 21, 2019 13:02
-
-
Save lorenzoaiello/4e78a35512618983c021b674b5f38583 to your computer and use it in GitHub Desktop.
PHP JSON String Fixer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fixJSON( $j ){ | |
$j = trim( $j ); | |
$j = ltrim( $j, '(' ); | |
$j = rtrim( $j, ')' ); | |
$a = preg_split('#(?<!\\\\)\"#', $j ); | |
for( $i=0; $i < count( $a ); $i+=2 ){ | |
$s = $a[$i]; | |
$s = preg_replace('#([^\s\[\]\{\}\:\,]+):#', '"\1":', $s ); | |
$a[$i] = $s; | |
} | |
$j = implode( '"', $a ); | |
return $j; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment