Created
          July 1, 2015 10:45 
        
      - 
      
- 
        Save qsorix/38f0cadac7dba8e444cb to your computer and use it in GitHub Desktop. 
    Duplicated json keys
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/env python | |
| import json | |
| import sys | |
| def list_duplicates(seq): | |
| seen = set() | |
| seen_add = seen.add | |
| # adds all elements it doesn't know yet to seen and all other to seen_twice | |
| seen_twice = set( x for x in seq if x in seen or seen_add(x) ) | |
| # turn the set into a list (as requested) | |
| return list( seen_twice ) | |
| def conflict(arg): | |
| keys = map(lambda x: x[0], arg) | |
| dups = list_duplicates(keys) | |
| if dups: | |
| print dups | |
| return arg | |
| content = open(sys.argv[1]).read() | |
| json.loads(content, object_pairs_hook=conflict) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment