0

how can I get the "symbol" data in a json data like below? I am using Python.

Also, how can I replace the "}" object in this data with replace?

[
{"symbol": "ZILUSDT", "positionAmt": "0", "entryPrice": "0.00000", "markPrice": "0.01728152", "unRealizedProfit": "0.00000000", "liquidationPrice": "0", "leverage": "20", "maxNotionalValue": "25000", "marginType": "cross", "isolatedMargin": "0.00000000", "isAutoAddMargin": "false", "positionSide": "SHORT"}, 
{"symbol": "FLMUSDT", "positionAmt": "0", "entryPrice": "0.0000", "markPrice": "0.00000000", "unRealizedProfit": "0.00000000", "liquidationPrice": "0", "leverage": "20", "maxNotionalValue": "25000", "marginType": "cross", "isolatedMargin": "0.00000000", "isAutoAddMargin": "false", "positionSide": "BOTH"}, 
{"symbol": "FLMUSDT", "positionAmt": "0", "entryPrice": "0.0000", "markPrice": "0.00000000", "unRealizedProfit": "0.00000000", "liquidationPrice": "0", "leverage": "20", "maxNotionalValue": "25000", "marginType": "cross", "isolatedMargin": "0.00000000", "isAutoAddMargin": "false", "positionSide": "LONG"}, 
{"symbol": "FLMUSDT", "positionAmt": "0", "entryPrice": "0.0000", "markPrice": "0.00000000", "unRealizedProfit": "0.00000000", "liquidationPrice": "0", "leverage": "20", "maxNotionalValue": "25000", "marginType": "cross", "isolatedMargin": "0.00000000", "isAutoAddMargin": "false", "positionSide": "SHORT"}
]
1
  • symbols = [x['symbol'] for x in data]. Commented Oct 30, 2020 at 15:58

3 Answers 3

0

You can iterate over the list of dictionaries after loading it as JSON (assuming it is d):

print(*[x['symbol'] for x in d],sep="\n")

Readable way:

for x in d:
  print(x['symbol'])

Load from a file:

import json
with open('json.txt') as f:
  d = json.load(f)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for the sample. How can I tabulate this with "pypi.org/project/Columnar"?
0

That is a list of dictionaries.

import json

with open('myfile.json') as file:
    items = json.load(file)

for item in items:
    print(item['symbol'])

3 Comments

Thank you very much for the sample. How can I tabulate this with "pypi.org/project/Columnar"?
@Fatihmzm Perhaps you should ask a new question for that.
I opened a new topic, can you help me? stackoverflow.com/questions/64612074/…
0

To read json data use the json.load() function.

# Python program to read 
# json file 


import json 

# Opening JSON file 
f = open('data.json',) 

# returns JSON object as 
# a dictionary 
data = json.load(f) 

# Iterating through the json 
# list 
for i in data['symbol']: 
    print(i) 

# Closing file 
f.close() 

Source https://www.geeksforgeeks.org/read-json-file-using-python/

4 Comments

I don't see an emp_details key in the sample data.
That's because it's referred to the source code I added to the bottom...thanks for pointing it out; I just edited it to print "symbol" as the question asks.
Thank you very much for the sample. How can I tabulate this with "pypi.org/project/Columnar"?
You should open a new question to ask that, anyway writing something like: data = [] table = columnar(data, headers=['Race', 'Date', 'Location', 'Distance'], patterns=patterns) print(table) And replacing print(i) with data.append(i)

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.