Rik Heywood
Rik Heywood

Reputation: 13972

What is the correct way to escape text in JSON responses?

I am generating the json from PHP.

Upvotes: 3

Views: 18245

Answers (2)

Stepan Stolyarov
Stepan Stolyarov

Reputation: 647

The JSON is just a subset of Javascript, so everything you know about escaping strings in Javascript applies to JSON.

And yes, the correct answer is to use one of library functions, there is a quite a few of them around: see A completely fair and balanced comparison of php json libraries.

Upvotes: 2

Greg
Greg

Reputation: 321668

The correct way is to use json_encode()

Upvotes: 19

Related Questions