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

Avnesh Shakya avnesh.nitk at gmail.com
Mon May 27 00:32:40 EDT 2013


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



More information about the Python-list mailing list