For AI agents: the complete documentation index is available at /tc39-atlas/en/llms.txt, the full documentation bundle is available at /tc39-atlas/en/llms-full.txt, and this page is available as Markdown at /tc39-atlas/en/proposals/year/pending/proposal-json-tryParse.md.
  • English
  • JSON.tryParse ?

    Proposal details
    Proposal overview

    This proposal introduces a JSON.tryParse method that returns undefined on parse failure instead of throwing an exception, simplifying the pattern of try-catch around JSON.parse. It was presented to TC39 but rejected in November 2023. The proposal includes spec pseudo-code showing a call to the existing JSON.parse with optional reviver, and cites URL.canParse as prior art for handling parse failures gracefully.

    Note

    The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.

    JSON.tryParse

    Rejected by tc39 on Nov 2023.

    Problem to solve

    try { return JSON.parse(str) } catch { return undefined }

    Prior art

    URL.canParse

    Spec

    JSON.parse ( _text_ [ , _reviver_ ] )
    
    1. Let _result_ be Completion(Call(%JSON.parse%, *null*, << _text_, _reviver_ >> )).
    1. If _result_ is an abrupt completion, return *undefined*.
    1. Return _result_.