http://stackoverflow.com/questions/1083250/running-json-through-pythons-eval
On Mar 22, 2014 7:48 PM, "Rajiv Subramanian M"
wrote:
> Hi dhuruv,
>
> I know null cases exists. I will throw an exception "UN defined variable
> null". But you can solve it by declare a variable
>
> null = None
>
> Then
Hi dhuruv,
I know null cases exists. I will throw an exception "UN defined variable
null". But you can solve it by declare a variable
null = None
Then execute the eval command. Any issues?
___
BangPypers mailing list
BangPypers@python.org
https://mail.
;
> > Can you share your thoughts on how to parse a JSON file by using python?
> >
> > Thanks,
> > Lokesh.
> >
> > --
> >
> > Message: 2
> > Date: Fri, 21 Mar 2014 14:08:27 +0530
> > From: Noufal Ibrahim KV
)
>2. Re: JSON PARSER (Rajiv) (Jayanth Koushik)
>
>
> ------------------
>
> Message: 1
> Date: Fri, 21 Mar 2014 15:26:37 +0530
> From: Rajiv Subramanian M
> To: bangpypers@python.org
> Subject: Re: [BangP
On Fri, Mar 21 2014, lokesh bobby wrote:
> Hi Prashant,
>
> I have 2 concerns here
>
> 1. As I mentioned earlier, my file consists of more than 2 lac
> lines. So it is not possible to load that many number of lines inside
> json.loads(). We need to pass the file, which itself is a limitation
> as
Hi Prashant,
I have 2 concerns here
1. As I mentioned earlier, my file consists of more than 2 lac lines. So it is
not possible to load that many number of lines inside json.loads(). We need to
pass the file, which itself is a limitation as explained earlier.
2. It is not an ideal solution for
EDIT :
import simplejson as json
from collections import defaultdict
def duplicate_key_lookup(ordered_pairs):
"""Convert duplicate keys values to lists."""
# read all values into lists
d = defaultdict(list)
for k, v in ordered_pairs:
d[k].append(v)
# unpack list
> >4. Re: JSON PARSER (Vishal)
> > 5. Re: JSON PARSER (lokesh bobby)
> >6. Re: JSON PARSER (Jayanth Koushik)
> >
> >
> > --
> >
> > Message: 1
> > Date: Fri, 2
Hello Lokesh ,
as we know json.loads return data in form of dict and dict can never have
same keys .
so we can do one thing and that is to return a list of all values which are
having same names.
import simplejson as json
from collections import defaultdict
def duplicate_key_lookup(ordered_pair
: lokesh bobby
>> > To: Bangalore Python Users Group - India
>> > Subject: [BangPypers] JSON PARSER
>> > Message-ID:
>> > <1395389920.23044.yahoomail...@web193806.mail.sg3.yahoo.com>
>> > Content-Type: text/plain; charset=utf-8
>> &g
; Here i am using pprint to print result data (You can have a look
> http://docs.python.org/2/library/pprint.html )
> Or
> You can also use simplejson library to do same . (
> http://simplejson.readthedocs.org/en/latest/ )
>
>
>
>
> On Fri, Mar 21, 2014 at 2:08 PM, Noufal Ibrahim KV
Hi Jayanth/Prashant,
Either "the duplicates to be loaded" or "An ouput of all the duplicate key
names in a JSON file" should be fine for me :-)
NOTE: JSON file consits of more than 2 lakhs LOC
Lokesh
On Friday, 21 March 2014 3:17 PM, Jayanth Koushik wrote:
Hi Prashant
I think he wants th
Hi Prashant
I think he wants the duplicates to be loaded, not cause an exception.
Jayanth
On Fri, Mar 21, 2014 at 3:15 PM, Prashant Gaur <91prashantg...@gmail.com>wrote:
> Hi Lokesh,
>
> we can pass lookup while parsing your json file which will make sure that
> name is repetitive or not .
>
>
Hi Lokesh,
we can pass lookup while parsing your json file which will make sure that
name is repetitive or not .
import json
def duplicate_checking_hook(pairs):
''' lookup for duplicate names'''
result = dict()
for key, val in pairs:
if key in result:
raise KeyErr
Hi Jayanth,
Ideally speaking a JSON shouldn't be created with repetitive key names. But
manually it is possible that a proper JSON file can be appended with a
duplicate key. We need to catch that duplicate key. If we are going to use
json.load(), the repetitive keys of the JSON file wont get lo
Hi Lokesh
The 'problem' that you talk about isn't really a problem. Since the JSON
specification does not say what is to be done for repeated names, it is up
to the implementation to decide. What is your requirement for handling
repeated names?
Jayanth
On Fri, Mar 21, 2014 at 2:30 PM, lokesh bo
Hi Noufal,
Thanks for your reply. I am not looking for loading the JSON file. There is a
limitation in it. Go thru the links
http://docs.python.org/2/library/json.html#repeated-names-within-an-object
http://docs.python.org/3.2/library/json.html#repeated-names-within-an-object
In order to get ri
Hi,
I have used simplejson and ultrajson. Found ultrajson to be the fastest
amongst known libraries for Python
UltraJSON (
http://pushingtheweb.com/2011/03/ultra-fast-json-encoding-decoding-python/)
Compare performance: http://stackoverflow.com/a/15440843
Download it from here: https://pypi.pyth
Python provides json module to parse JSON files.
import json
from pprint import pprint
with open('data.json') as json_file:
data = json.load(json_file)
pprint(data)
Here i am using pprint to print result data (You can have a look
http://docs.python.org/2/library/pprint.html )
Or
You can also
On Fri, Mar 21 2014, lokesh bobby wrote:
> Hi ALL,
>
> Can you share your thoughts on how to parse a JSON file by using
> python?
import json
with open("data.json") as f:
json.load(f)
[...]
--
Cordially,
Noufal
http://nibrahim.net.in
___
Bang
20 matches
Mail list logo