A well formed JSON string can be an JS Object, but not the other way around due to JS allow you to use keys without quotes, or use single quotes.
Example:
JS Object Literal | JSON |
---|---|
{foo: 'bar'} |
{"foo": "bar"} |
Here is a simple HTML that can convert a JS object literal into JSON string:
<<< @/blog/.vuepress/public/apps/js-to-json.html
You can run it here