858. Convert Objects to JSON String
Return a valid JSON string with the specified value. The value may be null, boolean, array, object, string, or number. There shouldn't be any extra spaces in the returned string. The keys should be in the same order as the one that Object.keys() returns.
Do not use the built-in JSON.stringify technique to solve it.
Example 1:
Input : object = { "x" : "a" }
Output : {"x":"a"}
Explanation :
We remove the extra whitespaces and return it as a string.
Example 2:
Input : object = {"key":{"a":1,"b":[{},null,"Hello"]}}
Output : {"key":{"a":1,"b":[{},null,"Hello"]}}
Explanation:
Objects and arrays can include other objects and arrays.
Now Your Turn!
Pick the correct output for the given inputInput : object = {"x": "true"}
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- Value is a valid JSON value
- 1 <= JSON.stringify(object).length <= 104
- maxNestingLevel <= 100
- All strings contain only alphanumeric characters