Create JSON from a String

In JavaScript:

An object literal, which uses the {} syntax, consists of a collection of property: value pairs.

An array literal, which uses the [] syntax, consists of a collection of values.

[begin: "test1", end: "test2"]

You have used the array syntax here, but have tried to put property: value pairs inside it.

This causes your error, the : isn’t expected.

You probably want to use the {} there. Alternatively, you want to remove begin: and end:.


This has nothing to do with JSON or strings. It is simply JavaScript.

Leave a Comment