Implement a JSON Parser in JS

Publié le: 31 décembre 2023
sur la chaîne: Team AlgoDaily
1,227
8

Try to implement a JSON Parser in JS at https://algodaily.com/challenges/impl...

---

In JavaScript by default, there is a method that can parse a given JSON string, and it can be invoked by calling `JSON.parse()`. The way this method works is constructing the JavaScript value or object described by the string.

Can you implement your own version of this method, called `parseJSON`, accepting one parameter (the JSON string), keeping in mind all the value types and restrictions in the JSON format?

```js
function parseJSON(input) {
// fill in this method
}
```

Your task is to create a function called `parseJSON` that takes a string as input and returns the corresponding JavaScript object. The function should be able to handle JSON-like strings, which can be:

Primitive types: `null`, `true`, `false`
Strings wrapped in quotes: `"string"`
Arrays: `[1, "a", null]`
Objects: `{"key": "value", "anotherKey": 42}`

Your parser should return the corresponding JavaScript types for these string inputs. For example, if the input string is `"null"`, your function should return `null`.


Sur cette page du site, vous pouvez voir la vidéo en ligne Implement a JSON Parser in JS durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Team AlgoDaily 31 décembre 2023, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 1,227 fois et il a aimé 8 téléspectateurs. Bon visionnage!