Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8602267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:02:37+00:00 2026-06-12T02:02:37+00:00

console.log(JSON.parse(‘{data:{\json\:\rocks\}}’)); gives error (tested on Firefox and Chrome’s console). Is this a bug with

  • 0
console.log(JSON.parse('{"data":"{\"json\":\"rocks\"}"}'));

gives error (tested on Firefox and Chrome’s console). Is this a bug with JSON.parse? Same decodes well when tested with PHP.

print_r(json_decode('{"data":"{\"json\":\"rocks\"}"}', true));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:02:38+00:00Added an answer on June 12, 2026 at 2:02 am

    This string is processed differently in PHP and JS, i.e. you get different results.

    The only escapes sequences in single quoted strings in PHP are \\ and \'. All others are outputted literally, according to the documentation:

    To specify a literal single quote, escape it with a backslash (\). To specify a literal backslash, double it (\\). All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as \r or \n, will be output literally as specified rather than having any special meaning.

    In JS on the other hand, if a string contains an invalid escape sequence, the backslash is discarded (CV means character value):

    • The CV of CharacterEscapeSequence :: NonEscapeCharacter is the CV of the NonEscapeCharacter.
    • The CV of NonEscapeCharacter :: SourceCharacter but not EscapeCharacter or LineTerminator is the SourceCharacter character itself.

    The quote might not be helpful by itself, but if you follow the link and have a look at the grammar, it should become clear.


    So in PHP the string will literally contain \" while in JS it will only contains ", which makes it invalid JSON:

    {"data":"{"json":"rocks"}"}
    

    If you want to create a literal backslash in JS, you have to escape it:

    '{"data":"{\\"json\\":\\"rocks\\"}"}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See this code: var jsonString = '{id:714341252076979033,type:FUZZY}'; var jsonParsed = JSON.parse(jsonString); console.log(jsonString, jsonParsed); When
var jsn=getAttr(ref,json-data).toString(); console.log(jsn); //{test: true,stringtest:hallo}. it's OK. JSON.parse(jsn); //Uncaught SyntaxError: Unexpected token s, line:
$.getJSON('http://twitter.com/followers/ids.json?screen_name=' + query1 + '&callback=?', function (data) { console.log('JSON data string 1 is: '
var list = []; $.getJSON(json.js, function(data) { $.each(data, function(i, item) { console.log(item.text); list.push(item.text); });
I have reason to believe console.log and JSON.stringify can produce inconsistent views of the
Any advice how to console.log the element that fired an hover action? This is
I want to parse this json using jquery and each with a loop. I
This is my JSON from PHP: {data : [ { _id : { $id
If I console log test I get [ { property_1: a, property_2: b, }
Why do console.log(/a/ == /a/); and var regexp1 = /a/; var regexp2 = /a/;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.