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

  • SEARCH
  • Home
  • 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 8382725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:59:37+00:00 2026-06-09T16:59:37+00:00

When parsing json using jQuery.parseJSON(), I get this error SyntaxError: JSON.parse: bad control character

  • 0

When parsing json using jQuery.parseJSON(), I get this error

SyntaxError: JSON.parse: bad control character in string literal

A quick search revelead that this is caused by newlines in the json string.

I get my json string from PHP using json_encode().

Is there a way to encode it in such a way that jQuery.parseJSON() would not complain and still retain the newline information?

  • 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-09T16:59:38+00:00Added an answer on June 9, 2026 at 4:59 pm

    According to the v8 bug tracker (http://code.google.com/p/v8/issues/detail?id=616), this is actually the correct behavior:

    “Newlines are not allowed inside JSON strings (no control characters are, see, e.g.,
    JsonStringCharacter production of ECMA262 5ed, section 15.2.1.1).”

    So it depends really on what you want to do – in this instance, as you need the newlines, you need to escape them before doing the json parse:

    //myjsonobject contains the json object
    
    var obj = jQuery.parseJSON(myjsonobject.replace(/\n/g,"\\n"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm retreiving a JSON string and parsing it with jQuery with $.getJSON. After I
I'm trying to get a jSON response using jQuery 1.5.1 with mvc3 and the
I'm having difficulty parsing some JSON data returned from my server using jQuery.ajax() To
I am receiving JSON string response from my WCF service. I wanna parse this
I am using JSON parsing, I put data in array named JSON Array .
I m using JSON and while parsing, i m getting the returned value as
I'm using the code below for Android JSON parsing but I am getting the
I am using google Api for custom search and have done the json Parsing.
I'm attempting to retrieve a JSON file from an API for parsing. I'm using
I'm parsing JSON that is contained in an HTML element. Consider this markup: <div

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.