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?

Newsgroups comp.lang.python
Date 2013-05-26 21:32 -0700
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>

Show all headers | 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