How to make invalid json valid?

  • 0
    Hello everyone. I receive an invalid json with comments, something like this:
    "version": "1",              //version maker,
     /** DATA **/

    How to make this 'json' valid? Maybe there is some kind of library? Regulars I can’t even imagine how to parse this.
    JavaScript Anonymous, Aug 26, 2020

  • 2 Answers
  • 0
    This is called json5 . Use the cocoa thread ready lib for parsing and you will be happy.

  • 0
    If you are sure of the source of this when and of its validity, then you can interpret it as JS and not JSON

    const str = `{
    "version": "1", //version maker,
    /** DATA **/

    const obj = eval(`(${str})`)

    obj.version // "1"

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!