Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

How to retrieve the value in a json file using data.get

$
0
0

I was able to retrieve values for values data1, data2... using data.get function in Python.

data = json.load(file.json)print(f"##vso[task.setvariable variable=var1;isOutput=true]{data.get('A', {}).get('key1', {})}")

However, I wish to make use of the same technique to retrieve the values X and Y for some particular syntax checking on my json file.

{"A": {"key1": "data1""key2": "data2","key3": "data3"    },"B": {"X": {"key4": "data4",        },"Y": {"key5": "data5",        }    }}

I tried to use the following but I am also getting the keys key4 and key5 on B.

print(f"##vso[task.setvariable variable=var1;isoutput=true]{data.get('B', {})}")

I only wanted to get the value of X or Y itself and not what is mapped inside.

Can anyone please help? Thanks!


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>