|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42708 json_decode: escape characters
Submitted: 2007-09-19 10:19 UTC Modified: 2008-07-22 17:33 UTC
Avg. Score:4.8 ± 0.4
Reproduced:13 of 13 (100.0%)
Same Version:7 (53.8%)
Same OS:8 (61.5%)
From: tjerk dot meesters at muvee dot com Assigned:
Status: Wont fix Package: JSON related
PHP Version: 5.2.4 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: tjerk dot meesters at muvee dot com
New email:
PHP Version: OS:


 [2007-09-19 10:19 UTC] tjerk dot meesters at muvee dot com
When a single quote is being escaped, the json_decode() gives some unexpected results.

1. According to the JSON specs, the single quote is not in the list of characters that can follow the escape character (such as n, t, b, r, etc.); however, JavaScript does recognize the single quote so it would be very nice to have as a feature.

2. When wrapping a string with an escaped single quote inside an array context, the json_decode() gives up and returns NULL.

Reproduce code:

$s = '"Sir, you\\\'re an idiot!"';


Expected result:
string(21) "Sir, you're an idiot!"
array(1) {
  string(21) "Sir, you're an idiot!"

Actual result:
string(22) "Sir, you\'re an idiot!"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-11-23 00:45 UTC]

string(22) "Sir, you\'re an idiot!"


string(22) "Sir, you\'re an idiot!"
string(26) "["Sir, you\'re an idiot!"]"
 [2008-07-22 17:33 UTC]
1. "Fixing" this would violate the JSON spec. HEAD (aka PHP 6) also behaves the same way now as other branches.

2. NULL is returned whenever you pass invalid data to json_decode().
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Sep 24 21:01:24 2023 UTC