Practice/Meta/Leetcode 2759. Convert JSON String to Object
CodingOptional
Create a parser that takes a valid JSON-formatted string as input and converts it into the appropriate native data structure. Your parser must handle all standard JSON types: objects (key-value mappings), arrays, strings with escape sequences, numbers (integers and decimals), booleans, and null values.
The parser should process the string character by character, building the nested structure while respecting JSON syntax rules. It must correctly handle whitespace, nested structures of arbitrary depth, and string escape sequences like \n, \t, \", and \\.
true and falsenull as a valid valueExample 1:
Input: '{"name": "Charlie", "age": 25}' Output: \{"name": "Charlie", "age": 25\} Explanation: A simple object with two properties is parsed into a dictionary/object with string and number values.
Example 2:
Input: '[1, 2, 3, 4, 5]' Output: [1, 2, 3, 4, 5] Explanation: An array of integers is parsed into a list/array.
Example 3:
Input: '{"items": [true, false, null], "count": 3}' Output: \{"items": [true, false, null], "count": 3\} Explanation: An object containing an array of boolean and null values, plus a number property.
Example 4:
Input: '{"text": "Hello\\nWorld"}' Output: \{"text": "Hello\nWorld"\} Explanation: The escape sequence \\n is interpreted as an actual newline character.