0

I have the following market data in JSON format:

[
 {
  "date":1405728000,
  "high":0.005,
  "low":0.00406,
  "open":0.00411473,
  "close":0.00461299,
  "volume":183.76967581,
  "quoteVolume":40579.4327267,
  "weightedAverage":0.00452864
 },
 {
  /* same structure */
 },
 ...
]

I am trying to read it in assigning 1 variable for the close price for example:

import json


with open('1.json') as data_file:    
    data = json.load(data_file)


print data[0]["close"]

But this only reads in the first value for the close objects. How to put all "close" objects in 1 array?

Sorry I am amateur with arrays, so I'd like to know how to put all price types in their separate array variable.

3 Answers 3

3
import json


with open('1.json') as data_file:
    data = json.load(data_file)


print([row['close'] for row in data])
Sign up to request clarification or add additional context in comments.

Comments

1

Try it like this:

[item['close'] for item in data]

Comments

-1

Try this:

import json
data = json.load(open('1.json', 'r'))
print(data)
print(data[0]["close"])

If its possible, pass the absolute path for the file 1.json

1 Comment

this wont print all close keys in json obj.

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.