-2

I need to compare 2 JSONs, both have the same key, but different values within each key. I need to compare the percentage match between the two values.

For example: JSON 1:

{
    'education': {'name': 'Mount Carmel College', 'grade': '83'}
}

JSON 2:

{
    'education': {'name': 'bachelors in Mount Carmel College', 'grade': '83%'}
}

I need to check what percentage of the data in JSON 1 matches JSON 2. It is also to be noted that the 2 JSONs will not be in order.

I cannot use regex because it will only tell me if the data in one JSON exists in another JSON. It will not be able to give me how good of a match it is.

Baris Senyerli
  • 642
  • 7
  • 13

2 Answers2

0

Not sure whether you can achieve this directly, but just a though. What if you find the difference between two literal strings and get the percentage rather than narrowing it as a json string. Probably you may have to convert your jsons into strings first

https://stackoverflow.com/a/20726306/1338588

Kulasangar
  • 9,046
  • 5
  • 51
  • 82
0

Thank You for all your suggestions. I have settle on the following solution:

  1. Create two lists of the strings in each json.
  2. Do a one-many calculation of Levenshtein distance and select the pairs with the least distance.
Baris Senyerli
  • 642
  • 7
  • 13