Skip to content

Commit

Permalink
README: Replace deserialize eval with JSON.parse (#38)
Browse files Browse the repository at this point in the history
This updates README.md to suggest using [JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) instead of eval to address security concerns.
  • Loading branch information
unlobito committed Jan 9, 2024
1 parent ac79a5a commit 85b0435
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions README.md
Expand Up @@ -117,15 +117,7 @@ serialize(obj, {ignoreFunction: true});

## Deserializing

For some use cases you might also need to deserialize the string. This is explicitly not part of this module. However, you can easily write it yourself:

```js
function deserialize(serializedJavascript){
return eval('(' + serializedJavascript + ')');
}
```

**Note:** Don't forget the parentheses around the serialized javascript, as the opening bracket `{` will be considered to be the start of a body.
For some use cases you might also need to deserialize the string. Modern browsers support using [JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) to deserialize JSON, which protects against malicious scripts being executed through malformed JSON.

## License

Expand Down

0 comments on commit 85b0435

Please sign in to comment.