{ "data": { "question": { "questionId": "2745", "questionFrontendId": "2633", "boundTopicId": null, "title": "Convert Object to JSON String", "titleSlug": "convert-object-to-json-string", "content": "
Given an object, return a valid JSON string of that object. You may assume the object only inludes strings, integers, arrays, objects, booleans, and null. The returned string should not include extra spaces. The order of keys should be the same as the order returned by Object.keys()
.
Please solve it without using the built-in JSON.stringify
method.
\n
Example 1:
\n\n\nInput: object = {"y":1,"x":2}\nOutput: {"y":1,"x":2}\nExplanation: \nReturn the JSON representation.\nNote that the order of keys should be the same as the order returned by Object.keys().\n\n
Example 2:
\n\n\nInput: object = {"a":"str","b":-12,"c":true,"d":null}\nOutput: {"a":"str","b":-12,"c":true,"d":null}\nExplanation:\nThe primitives of JSON are strings, numbers, booleans, and null.\n\n\n
Example 3:
\n\n\nInput: object = {"key":{"a":1,"b":[{},null,"Hello"]}}\nOutput: {"key":{"a":1,"b":[{},null,"Hello"]}}\nExplanation:\nObjects and arrays can include other objects and arrays.\n\n\n
Example 4:
\n\n\nInput: object = true\nOutput: true\nExplanation:\nPrimitive types are valid inputs.\n\n
\n
Constraints:
\n\nobject includes strings, integers, booleans, arrays, objects, and null
1 <= JSON.stringify(object).length <= 105
maxNestingLevel <= 1000
Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES6 features.
lodash.js library is included by default.
\\r\\n\\r\\nFor Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.
\"], \"typescript\": [\"Typescript\", \"TypeScript 4.5.4, Node.js 16.13.2
.
Your code is run with --harmony
flag, enabling new ES2020 features.
lodash.js library is included by default.
\"]}", "libraryUrl": null, "adminUrl": null, "challengeQuestion": null, "__typename": "QuestionNode" } } }