0

I am new at working with JSON objects and I have been trying to find an answer on here but the common method I have seen being used is not working for me.

I am trying to get the value 21 from the JSON object I can inspect in my javascript console.

^Object { number: Object }
    ^number: Object
        min: 21
    >_proto_: Object

The name of the JSON object is answer so I tried to use JSON.parse

obj = JSON.parse(answer);
console.log(answer.min);

Or this

obj = JSON.parse(answer);
console.log(answer.number.min);

I know I'm missing something simple but I'm a visual learner and the docs don't do much for me.

4
  • 1
    try obj['min'] or obj.min Commented May 22, 2015 at 19:56
  • What is the console saying? Is there any error? JSON.parse() will turn a string in JSON format into a Javascript object. JSON.stringify() does the opposite. Commented May 22, 2015 at 20:00
  • Based on all of your comments on other answers, your question does not have enough details of the issue. They've answered the question based on what you've given us, but it sounds like that's still now working. Post a fiddle demonstrating the error. If console.log(answer) shows what you've pasted there, then answer.number.min === 21 -- see jsBin Commented May 22, 2015 at 20:00
  • What is a JSON object? Is that sort of like a JavaScript object? Commented May 22, 2015 at 20:01

2 Answers 2

1

I saw the comment fields from another post, and if answer really is just an object, then the following should work.

obj = answer.number.min

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

Comments

0

I'm guessing you need obj.number.min, provided answer is a string.

4 Comments

I just tried it and still nothing gets logged to the console.
Then why are you parsing it?
I've been looking to it for the past hour so I thought I'd head over here and ask. I don't really know how to get my value. I just need that number 21 to be saved in a variable.
we need more context. JSON.parse might be throwing

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.