Converting a String into a Dictionary

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cyanic Cipher

Hey, I need help converting a string into a dictionary. The text in question is formatted as follows:

{key:value, key2:value, key3:value}

I’ve tried JSON.parse() on it, but it returns with the error “Expected key”

I’ve also tried it on:

{key:{key:value, key2:value, key3:value}}

:bust_in_silhouette: Reply From: AlexTheRegent

JSON require all strings to be escaped with double quotes. To make it work, your text should be formatted as following:

{ "key": "value", "key2": "value", "key3": "value" }
or
{"key":{"key":"value", "key2":"value", "key3":"value"}}