850. Convert JSON String to Object

Given a string str, return the corresponding parsed JSON object parsedStr. You may assume that str is a valid JSON string, meaning it only contains strings, numbers, arrays, objects, booleans, and null. The string str will not include any invisible or escape characters.

Important :

Solve this problem without using the built-in JSON.parse method.

Example 1:

Input : str = '{"x":10,"y":[4,5,6]}'

Output : {"x":10,"y":[4,5,6]}

Explanation :

The JSON string represents an object with a number property x and an array property y. The function returns the corresponding object.

Example 2:

Input : str = 'false'

Output : false

Explanation :

The input is a primitive JSON value. The function correctly returns the boolean value false.

Now Your Turn!

Pick the correct output for the given input

Input : str = '["hello",123,{"z":null}]'

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • str is a valid JSON string.
  • 1 <= str.length <= 10⁵

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
var jsonParse = function (str) {
// Your Code goes here
};
Test Case

Input:

Str