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?

2
  • How are you passing this to javascript? Commented May 8, 2017 at 0:52
  • @charlietfl web sockets Commented May 8, 2017 at 1:16

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.