Convert JSON String to Object - Problem
Given a string str, return the parsed JSON object parsedStr. You may assume the str is a valid JSON string that only includes strings, numbers, arrays, objects, booleans, and null. The string will not include invisible characters and escape characters.
Please solve it without using the built-in JSON.parse method.
Input & Output
Example 1 — Simple Object
$
Input:
str = "{\"name\":\"John\",\"age\":30}"
›
Output:
{"name":"John","age":30}
💡 Note:
Parse JSON object with string and number values. The parser identifies the object structure and extracts key-value pairs.
Example 2 — Array with Mixed Types
$
Input:
str = "[1,true,null,\"hello\"]"
›
Output:
[1,true,null,"hello"]
💡 Note:
Parse JSON array containing different data types: number, boolean, null, and string.
Example 3 — Simple String
$
Input:
str = "\"hello world\""
›
Output:
hello world
💡 Note:
Parse a simple JSON string by removing the surrounding quotes.
Constraints
- 1 ≤ str.length ≤ 104
- str is a valid JSON string
- str contains only printable ASCII characters
- No escape sequences in strings
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code