Creating a JSON Object in Javascript

PHOTO EMBED

Saved by @infinitywars1_4k #javascript #json #objects #jsvariables

var eventsVariable = '"{events":[' +
    '{"location": "New York", "date": "May 1", "public": "true"},' +
    '{"location": "London", "date": "Apr 24", "public": "false"},' +
    '{"location": "San Frans", "date": "Nov 30", "public": "false"}]}';
    
content_copyCOPY

When declaring an JSON object variable, you need to wrap the object in 'single commas like this'. Wrap each line in single commas and end line breaks with a plus sign. eventsVariable will look like this: {"events":[ {"location": "New York", "date": "May 1", "public": "true"}, {"location": "London", "date": "Apr 24", "public": "false"}, {"location": "San Frans", "date": "Nov 30", "public": "false"} ]}