Created
October 19, 2016 03:32
-
-
Save aNd1coder/113961f920a634d4bdc03c5b746fe9fc to your computer and use it in GitHub Desktop.
Convert php object to json in nodejs
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 PHP2JSON(phpFilePath) { | |
return new Promise(function(resolve, reject) { | |
childProcess.exec( | |
'php -r \'include("' + phpFilePath + '"); print json_encode($php_object);\'', | |
function(err, stdout, stderr) { | |
if (err) { | |
console.log(err) | |
return | |
} | |
resolve(JSON.parse(stdout)) | |
} | |
) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment