Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46164
| References | <355f934e-bda0-4316-96bb-583c498ecb1a@googlegroups.com> <bb5d992b-4592-4777-ae47-3b3e090703a1@d8g2000pbe.googlegroups.com> |
|---|---|
| Date | 2013-05-27 10:35 +0530 |
| Subject | Re: how to compare two json file line by line using python? |
| From | Avnesh Shakya <avnesh.nitk@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2230.1369631143.3114.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
Actually, I am extracting data from other site in json format and I want to
put it in my database and when I extract data again then I want to compare
last json file, if these are same then no issue otherwise i will add new
data in database, so here may be every time data can be changed or may be
not so I think sorting is required, but if i compare line by line that will
be good, I am thinking in this way...
On Mon, May 27, 2013 at 10:21 AM, rusi <rustompmody@gmail.com> wrote:
> On May 27, 9:32 am, Avnesh Shakya <avnesh.n...@gmail.com> wrote:
> > hi,
> > how to compare two json file line by line using python? Actually I am
> doing it in this way..
> >
> > import simplejson as json
> > def compare():
> > newJsonFile= open('newData.json')
> > lastJsonFile= open('version1.json')
> > newLines = newJsonFile.readlines()
> > print newLines
> > sortedNew = sorted([repr(x) for x in newJsonFile])
> > sortedLast = sorted([repr(x) for x in lastJsonFile])
> > print(sortedNew == sortedLast)
> >
> > compare()
> >
> > But I want to compare line by line and value by value. but i found that
> json data is unordered data, so how can i compare them without sorting it.
> please give me some idea about it. I am new for it.
> > I want to check every value line by line.
> >
> > Thanks
>
> It really depends on what is your notion that the two files are same
> or not.
>
> For example does extra/deleted non-significant white-space matter?
>
> By and large there are two approaches:
> 1. Treat json as serialized python data-structures, (and so) read in
> the data-structures into python and compare there
>
> 2. Ignore the fact that the json file is a json file; just treat it as
> text and use string compare operations
>
> Naturally there could be other considerations: the files could be huge
> and so you might want some hybrid of json and text approaches
> etc etc
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
how to compare two json file line by line using python? Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-05-26 21:32 -0700
Re: how to compare two json file line by line using python? rusi <rustompmody@gmail.com> - 2013-05-26 21:51 -0700
Re: how to compare two json file line by line using python? Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-05-27 10:35 +0530
Re: how to compare two json file line by line using python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-27 05:33 +0000
Re: how to compare two json file line by line using python? Avnesh Shakya <avnesh.nitk@gmail.com> - 2013-05-27 11:58 +0530
Re: how to compare two json file line by line using python? Grant Edwards <invalid@invalid.invalid> - 2013-05-28 16:00 +0000
Re: how to compare two json file line by line using python? Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-27 10:50 +0000
csiph-web