0

Using javascript how can convert a String

let string = '{lat:41.66787,lng:25.54585,color:0,title:My_Title,snippet:My_Snippet,draggable:false}'

to JSON like

let json = {"lat":41.66787,"lng":25.54585,"color":0,"title":"My_title","snippet":"My_Snippet","dragabple":false}
Spectric
  • 30,714
  • 6
  • 20
  • 43
  • Have you tried to use `JSON.stringify(object);` – hurricane Jan 12 '22 at 19:08
  • @hurricane I don't see how `JSON.stringify` (or `JSON.parse`) could help here. The string isn't valid JSON. – jabaa Jan 12 '22 at 19:16
  • `let json = {"lat":41.66787,"lng":25.54585,"color":0,"title":"My_title","snippet":"My_Snippet","dragabple":false} ` isn't JSON. It's a JavaScript object literal. You should read: [What is the difference between JSON and Object Literal Notation?](https://stackoverflow.com/questions/2904131/what-is-the-difference-between-json-and-object-literal-notation). There is no JSON in your question. – jabaa Jan 12 '22 at 19:17
  • @Spectric The duplicate won't help here. The string isn't JSON. – jabaa Jan 12 '22 at 19:18
  • @jabaa question has been changed after my comment :) – hurricane Jan 12 '22 at 19:45
  • @hurricane Now, I get it. Yes, your comment made sense for the initial question. – jabaa Jan 12 '22 at 19:50
  • sorry, I'm a beginner and I may not have explained the problem correctly What I want is to convert this string object to JSON format so that I can then get the .obj such as obj.lat and obj.lng – antykaps Jan 12 '22 at 20:29

0 Answers0