I am trying to extract the particular key's value from the json Array in a file. I am trying to extrcat the value from the keys where ever the key is available anywhere in the json array. Here is the code that I am using:
from xml.dom.minidom import parseString
import json
def bar(somejson, key):
def val(node):
# Searches for the next Element Node containing Value
e = node.nextSibling
while e and e.nodeType != e.ELEMENT_NODE:
e = e.nextSibling
return (e.getElementsByTagName('string')[0].firstChild.nodeValue if e
else None)
# parse the JSON as XML
foo_dom = parseString(xmlrpclib.dumps((json.loads(somejson),)))
# and then search all the name tags which are P1's
# and use the val user function to get the value
return [val(node) for node in foo_dom.getElementsByTagName('name')
if node.firstChild.nodeValue in key]
This I have got from the question: How can I use python finding particular json value by key?
Now I am getting any error at the xmlrpclib
. I am not getting why it is coming. I tried to get the package using pip
but no such package is available for installation.
Kindly suggest me what should I do? The example of data is same as in the question link mentioned above.