#!/usr/bin/env python3 # Standalone synthetic fixture; no user files or external network. import json class Pairs(list):pass def inspect(source): tree=json.loads(source,object_pairs_hook=Pairs);duplicates=[] def walk(v,path=''): if isinstance(v,Pairs): seen=set();out={} for key,value in v: pointer=path+'/'+key.replace('~','~0').replace('/','~1') if key in seen:duplicates.append(pointer) seen.add(key);out[key]=walk(value,pointer) return out if isinstance(v,list):return [walk(x,path+'/'+str(i))for i,x in enumerate(v)] return v candidate=walk(tree) return {'duplicates':duplicates,'accepted':not duplicates,'value':candidate if not duplicates else None,'defaultParserValue':json.loads(source)} cases=[('nested','{"job":"J-91","status":"queued","status":"done","meta":{"currency":"KRW","currency":"USD"}}'),('escaped-name',r'{"a":1,"\u0061":2}'),('separate-objects','[{"id":1},{"id":2}]'),('normalization-distinct','{"é":1,"é":2}'),('slash-key','{"a/b":1,"a/b":2}')] results=[{'case':name,'source':source,**inspect(source)}for name,source in cases] assert results[0]['duplicates']==['/status','/meta/currency'] assert results[1]['duplicates']==['/a'] assert results[2]['accepted'] and results[3]['accepted'] assert results[4]['duplicates']==['/a~1b'] result={'cases':results,'blocked':sum(not r['accepted']for r in results),'accepted':sum(r['accepted']for r in results),'scope':'Decoded key equality within each object; no Unicode normalization or cross-object ID deduplication. A candidate with duplicate keys is never emitted as accepted output.'} import sys,json from datetime import datetime,timezone result={'experiment':'json-duplicate-key-detection','executedAt':datetime.now(timezone.utc).isoformat(),'runtime':sys.version.split()[0],'synthetic':True,**result} print(json.dumps(result,ensure_ascii=False,indent=2))