Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46157

how to compare two json file line by line using python?

X-Received by 10.224.36.66 with SMTP id s2mr14492808qad.6.1369629161116; Sun, 26 May 2013 21:32:41 -0700 (PDT)
X-Received by 10.50.44.69 with SMTP id c5mr326064igm.12.1369629161077; Sun, 26 May 2013 21:32:41 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!ch1no1297864qab.0!news-out.google.com!y6ni51517qax.0!nntp.google.com!ch1no1297861qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Sun, 26 May 2013 21:32:40 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=122.179.38.18; posting-account=o4PhMQoAAAD3VECHQD4L7c0EPfi-y8z2
NNTP-Posting-Host 122.179.38.18
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <355f934e-bda0-4316-96bb-583c498ecb1a@googlegroups.com> (permalink)
Subject how to compare two json file line by line using python?
From Avnesh Shakya <avnesh.nitk@gmail.com>
Injection-Date Mon, 27 May 2013 04:32:41 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.lang.python:46157

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


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