0

I want to a javascript make an array out of this JSON code

{

 Technical Analysis: RSI:{

 2017-07-07 16:00: {RSI: "50.2925"},

 2017-07-07 15:45: {RSI: "54.1255"},

 2017-07-07 15:30: {RSI: "55.0698"},

 2017-07-07 15:15: {RSI: "52.0587"},

 2017-07-07 15:00: {RSI: "55.4002"},

 2017-07-07 14:45: {RSI: "57.9093"}

}
}

I know how to do it generally, I mean it’s not rocket science, you just have to parse it and use a for in loop. But the thing is that the content I want to be inside the array, not only sits inside a key, it sits inside two keys! Therefore I don’t know how to access it. I would think that it has to be something like this:

parsedDoc[“Technical Analysis”]

or:

parsedDoc[“Technical Analysis: RSI”]

or:

parsedDoc[“Technical Analysis”][“RSI”]

But none of these seems to work, can anyone help me out here.

3
  • 1
    First of all this is not valid JSON. Correct your JSON errors and they try to parse your JSON object. Commented Jul 8, 2017 at 22:51
  • That is not JSON. The JSON spec for an object requires keys to be strings and therefore quoted. See json.org Commented Jul 8, 2017 at 22:51
  • Also note there are no arrays in any of what is shown Commented Jul 8, 2017 at 23:00

1 Answer 1

1

You have invalid JSON there, correct it to be valid JSON and your last approach will work.

A smaller version of your example that is valid JSON:

var parsedDoc = {
  "Technical Analysis": {
    "RSI":{
      "2017-07-07 16:00": {
        "RSI": "50.2925"
      }
    }
  }
}

now

parsedDoc["Technical Analysis"]["RSI"] returns:

"2017-07-07 16:00": { 
  "RSI": 50.2925
}
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.