-1

I have the below sample json file and I would like to get the value of ipAddress using python.

{
  "hostId" : "65cb096f-7adb-4197-0c61-b0a1a67236d4",
  "ipAddress" : "10.2.1.354",
  "hostname" : "localhost",
  "rackId" : "/default",
  "hostUrl" : "http://localhost:7180/cmf/hostRedirect/65cb096f-7adb-4197-0c61-b0a1a67236d4",
}

I can use grep tool in shellscript to do this but no sure how to do it in Python. Is there any specific tool in python like grep, awk or sed that shell does? My output should be 10.2.1.354.

Alex Raj Kaliamoorthy
  • 2,035
  • 3
  • 29
  • 46

1 Answers1

1

You can use this :

>>> import json
>>> f = open('file.json', 'r')
>>> obj = json.load(f)
>>> obj['ipAddress']
u'10.2.1.354'

Hope it'll be helpful.

3kt
  • 2,543
  • 1
  • 17
  • 29