How can I convert php's POST variable to json format?
2 Answers
If this is entirely in php, and you simply want to convert the data in $_POST to JSON, you can do so like this:
$json = json_encode($_POST);
Using php's built-in function json_encode (doc)
If this is not what you want to do, please be more specific with your question.
3 Comments
rails_noob
actually php POST -> array -> json
Code Magician
@downvoter kindly remove the downvote. My answer is correct, accepted and was first by a couple of seconds (sort by oldest to see for yourself)
Oscar Gonzalez
When using the line above, is there something you can do about someone POSTing a gigantic piece of content, which could cause
json_encode to perform poorly? Is that a concern for anyone?