Hi Jayanth,

I didn't get what you mean duplicate in json data...

And the output for the following
>>> eval("{'a': 1, 'b': 2}")

will be {'a': 1, 'b': 2}

It can't be {'a': 1}

because I believe eval() takes string argument and it will throw exception
only if that argument string doesn't met the valid syntax of Python..

Please provide an example json-data with duplicates.. so that I could
understand

On Fri, Mar 21, 2014 at 3:32 PM, <bangpypers-requ...@python.org> wrote:

> Send BangPypers mailing list submissions to
>         bangpypers@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/bangpypers
> or, via email, send a message with subject or body 'help' to
>         bangpypers-requ...@python.org
>
> You can reach the person managing the list at
>         bangpypers-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of BangPypers digest..."
>
>
> Today's Topics:
>
>    1. Re: JSON PARSER (Rajiv) (Rajiv Subramanian M)
>    2. Re: JSON PARSER (Rajiv) (Jayanth Koushik)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 21 Mar 2014 15:26:37 +0530
> From: Rajiv Subramanian M <rajiv.m1...@gmail.com>
> To: bangpypers@python.org
> Subject: Re: [BangPypers] JSON PARSER (Rajiv)
> Message-ID:
>         <
> caelut3xekoue8lbfwpytroomaxgnm4m_w_pqe-vaeoxd9nb...@mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
>
> why not use 'eval' keyword for parsing json..
>
> Here is an example.
>
> *with 'eval' *
>
>
> json_data ='''
> {
>     "firstName": "John",
>     "lastName" : "Smith",
>     "age"      : 25,
>     "address"  :
>     {
>         "streetAddress": "21 2nd Street",
>         "city"         : "New York",
>         "state"        : "NY",
>         "postalCode"   : "10021"
>     },
>     "phoneNumber":
>     [
>         {
>             "type"  : "home",
>             "number": "212 555-1234"
>         },
>         {
>             "type"  : "fax",
>             "number": "646 555-4567"
>         }
>     ]
> }'''
> d = eval('('+json_data+')')
> for key in d:
>     print(key, ':', d[key].__class__, d[key])
>
> *Output:*
>
>
> lastName : <class 'str'> Smith
> age : <class 'int'> 25
> phoneNumber : <class 'list'> [{'type': 'home', 'number': '212
> 555-1234'}, {'type': 'fax', 'number': '646 555-4567'}]
> firstName : <class 'str'> John
> address : <class 'dict'> {'postalCode': '10021', 'city': 'New York',
> 'streetAddress': '21 2nd Street', 'state': 'NY'}
>
> --
> Rajiv M
> Software Engineer.
>
> *DoubleSpring Media (P) Ltd.*   #15/1 Robertson Road, Frazer Town,
>
> Bangalore 05, IND.
> Office: +91-80-40917126,  Mobile: +91 7411 129611,  Skype:
> rajiv.m1991<http://lightness-rejoice.rhcloud.com>,
>  Web: www.doublespring.com.
>
>  <http://twitter.com/rajivm1991>  <http://facebook.com/rajivm1991>
>
>
> ------------------------------
>
> Message: 2
> Date: Fri, 21 Mar 2014 15:32:13 +0530
> From: Jayanth Koushik <jnkous...@gmail.com>
> To: Bangalore Python Users Group - India <bangpypers@python.org>
> Subject: Re: [BangPypers] JSON PARSER (Rajiv)
> Message-ID:
>         <
> ca+peiekbu2l30eoiqmfk6wh-y7jvh3fu5jxzgsm1fcqy-tz...@mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Sorry, I meant:
>
> >>> eval("{'a': 1, 'a': 2}")
> {'a': 2}
>
>
> On Fri, Mar 21, 2014 at 3:31 PM, Jayanth Koushik <jnkous...@gmail.com
> >wrote:
>
> > Hi Rajiv
> >
> > eval does not work with duplicates.
> >
> > >>> eval("{'a': 1, 'b': 2}")
> > {'a': 1}
_______________________________________________
BangPypers mailing list
BangPypers@python.org
https://mail.python.org/mailman/listinfo/bangpypers

Reply via email to