1

So, I have a ruby program that takes a hash and turns it into a JSON string (lets say the hash is #FFFFFF) and that JSON string is sent to a javascript program where it needs to get #FFFFFF out of the JSON string, i've tried JSON.parse(); to no avail, and JSON.stringify(); only returns this "{\"color\":\"#FFFFFF\"}" how do I get it to return just #FFFFFF in a javascript string?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
EPICBRONY
  • 45
  • 6

1 Answers1

3

The fact that the JSON originates from a Ruby hash is irrelevant. You have to JSON.parse the JSON string — but! then you also have to access the .color property of the resulting object

let json = '{"color":"#FFFFFF"}'
let data = JSON.parse(json)
console.log(data.color)
// #FFFFFF
Mulan
  • 129,518
  • 31
  • 228
  • 259