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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:50:23+00:00 2026-06-14T04:50:23+00:00

This is not about how to manage or correct a faulty JSON, it is

  • 0

This is not about how to manage or correct a faulty JSON, it is about how to explain to the user where the error is in the faulty JSON.

Is there a way to find out at which position in the JSON the parser failed.

I want to solve this problem in a node.js application so please keep your answers in that domain if possible.

When I use the built in JSON object and the parse method for a faulty JSON I only get the exception message SyntaxError: Unexpected string. I would like to find out where the error occurred.

Preferred would be a JSON.validate(json) that returned result ok/error and the error position. Something like this:

var faultyJsonToParse = '{"string":"value", "boolean": true"}';
var result = JSON.validate(faultyJsonToParse);
if (result.ok == true) {
   console.log('Good JSON, well done!');
} else {
   console.log('The validator found a \'' + result.error + '\' of type \'' + result.errorType + '\' in your JSON near position ' + result.position);
}

The wanted outcome of the above would be:

The validator found a 'SyntaxError' of type 'Unexpected string' in your JSON near position 35.
  • 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-14T04:50:24+00:00Added an answer on June 14, 2026 at 4:50 am

    Try jsonLint:

    var faultyJsonToParse = '{"string":"value", "boolean": true"}';
    
    try {
        jsonlint.parse(faultyJsonToParse)
    } catch(e) {
        document.write('<pre>' + e)
    }
    

    result:

    Error: Parse error on line 1:
    ...ue", "boolean": true"}
    -----------------------^
    Expecting 'EOF', '}', ',', ']', got 'undefined'
    

    (although jsonLint is a node project, it can also be used in web: simply grab https://github.com/zaach/jsonlint/blob/master/web/jsonlint.js)

    As @eh9 suggested, it makes sense to create a wrapper around the standard json parser to provide detailed exception info:

    JSON._parse = JSON.parse
    JSON.parse = function (json) {
        try {
            return JSON._parse(json)
        } catch(e) {
            jsonlint.parse(json)
        }
    }
    
    JSON.parse(someJson) // either a valid object, or an meaningful exception
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is not about which is the best, it is about which makes
(Note: This is not a question about what is the best way with code
I was wondering if there is a correct way to parse a JSON file
Note: this is NOT about concurrency. This is about the thread macro. I know
Ok, firstly this is not about forms this is about consistent layout as a
This question is not about caching. I need this in-memory table for many small
This question is not about 'best' barcode library recommendation, we use various products on
(note that this question is not about CAS, it's about the May fail spuriously
Note: I understand this is not strictly about development, but in the earlier threads
This is not a question about a specific framework. I am using plain php

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.