16

How can I convert php's POST variable to json format?

0

2 Answers 2

49

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.

Sign up to request clarification or add additional context in comments.

3 Comments

actually php POST -> array -> json
@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)
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?
3
json_encode($_POST);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.