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 8625003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:40:27+00:00 2026-06-12T07:40:27+00:00

jQuery uses JSON.parse() for a cross-browser solution when converting JSON-strings to objects using jQuery.parseJSON()

  • 0

jQuery uses JSON.parse() for a cross-browser solution when converting JSON-strings to objects using jQuery.parseJSON():

parseJSON: function( data ) {
    if ( !data || typeof data !== "string") {
        return null;
    }

    // Make sure leading/trailing whitespace is removed (IE can't handle it)
    data = jQuery.trim( data );

    // Attempt to parse using the native JSON parser first
    if ( window.JSON && window.JSON.parse ) {
        return window.JSON.parse( data );
    }

    // Make sure the incoming data is actual JSON
    // Logic borrowed from http://json.org/json2.js
    if ( rvalidchars.test( data.replace( rvalidescape, "@" )
        .replace( rvalidtokens, "]" )
        .replace( rvalidbraces, "")) ) {

        return ( new Function( "return " + data ) )();

    }
    jQuery.error( "Invalid JSON: " + data );
}

But why isn’t there a similar solution for converting objects to JSON using JSON.stringify? JSON.stringify doesn’t work in IE7 for example, unless you include json2.js. Is it something that’s on jQuerys roadmap?

  • 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-12T07:40:29+00:00Added an answer on June 12, 2026 at 7:40 am

    There isn’t a similar solution because jQuery internally does not need it. The current stance on it is If the core doesn’t need it, and it can be implemented using generally accepted methods (including json2.js or using the one built into all modern browsers) it doesn’t need to be in the core.

    For reference, https://forum.jquery.com/topic/jquery-encodejson

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an jquery ajax success function which uses a template to put json
This link shows you that jQuery uses (new Function(return + data))(); for older browsers,
I am using jQuery.ajax(...) to retrieve JSON data from an ASP.NET MVC service. When
I have made a chat script using php, mysql and jquery. It uses json
I am using the jquery form plugin which uses jquery ajax to do most
I am using jquery with json. My client pages generate json, which I store
I've written a CMS which uses the PHP function json_encode to send some data
I am developing an application using jQuery that uses cookies. Right now, it is
I have a data fetching method that uses jQuery.ajax() to fetch xml files. /*
I've built a page using jQuery that uses an async Ajax call. I'm trying

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.