Safe JSON Parse

JavaScript Easy 4 views
Back to Questions
Next Wrap Errors with Context Medium N

Problem Description

Input has two lines: first is a JSON string, second is a default value as JSON. If first line parses, print parsed JSON (stringified). If it fails, print the default JSON as output.

Input Format

Line1: raw string (not JSON). Line2: default JSON value.

Output Format

One line: JSON stringified output.

Sample Test Case

Input:
{bad json} 123
Output:
123

Constraints

Default value line is valid JSON.

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Next