JSON.stringify (Basic)

Difficulty: medium

Implement a function jsonStringify, similar to JSON.stringify, that converts a JavaScript value into a JSON string.

For this basic version, you only need to handle JSON-serializable values:

  • Booleans
  • Numbers
  • Null
  • Arrays
  • Plain Objects
  • Strings

Ignore the second and third optional parameters of the original API.

Example

jsonStringify({ foo: 'bar' }); // '{"foo":"bar"}'
jsonStringify([1, 2, "three"]); // '[1,2,"three"]'

More JS Coding

View all JS Coding →
JS CodingMedium

5. Throttle

JS CodingMedium

13. Deep Clone

JS CodingMedium

14. Event Emitter

JS CodingEasy

66. Promise Methods

JS CodingEasy

19. Memoize I

JS CodingMedium

86. API Retry

Related hubs

  • All JavaScript coding
  • JavaScript interview questions
  • JS polyfill interview questions
  • Debounce & throttle questions
  • React interview hub