0

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.

Community
  • 1
  • 1
Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139
  • Are you importing the `xmlrpclib` library? By the way this library is available on [`PyPi`](https://pypi.python.org/pypi/xmlrpclib) – Moinuddin Quadri Mar 16 '17 at 08:32
  • @MoinuddinQuadri How I can install it? I tried to setup but could not or is there a way to use it in my program. Please help. – Jaffer Wilson Mar 16 '17 at 08:36
  • @JafferWilson did you see my answer? It's still part of the standard library. – vallentin Mar 16 '17 at 08:36
  • @Vallentin oop I forgot to refresh. Ok I just need to use it using import... I am new to python3 a bit. so was not knowing. – Jaffer Wilson Mar 16 '17 at 08:38
  • You may find my answer to [this question](http://stackoverflow.com/questions/41777880/functions-that-help-to-understand-jsondict-structure) helpful. – PM 2Ring Mar 16 '17 at 08:41

1 Answers1

0

In Python 3 the xmlrpclib library was renamed to xmlrpc. dumps is now located in xmlrpc.client. So to fix your problem either do:

import xmlrpc.client as xmlrpclib

or replace xmlrpclib.dumps with xmlrpc.client.dumps and import xmlrpc.client.

vallentin
  • 23,478
  • 6
  • 59
  • 81