"""Actual Python/Node JSON parse round trips, authored data, existing Node required."""
import json,subprocess,shutil,sys
JS=r'''
let s='';process.stdin.setEncoding('utf8');process.stdin.on('data',x=>s+=x);process.stdin.on('end',()=>{let input=JSON.parse(s);let raw=input.raw;let a=JSON.parse(raw);let strings=JSON.parse(input.strings);process.stdout.write(JSON.stringify({node_version:process.version,number_types:a.map(x=>typeof x.id),numbers:a.map(x=>x.id),numbers_equal:a[0].id===a[1].id,serialized:JSON.stringify(a),from_rounded_number_bigint:BigInt(a[1].id).toString(),string_types:strings.map(x=>typeof x.id),strings:strings.map(x=>x.id),strings_equal:strings[0].id===strings[1].id,strings_serialized:JSON.stringify(strings),from_original_digits_bigint:BigInt(strings[1].id).toString()}));});
'''
def demo():
    raw='[{"id":9007199254740992},{"id":9007199254740993}]';strings='[{"id":"9007199254740992"},{"id":"9007199254740993"}]'
    py=json.loads(raw);assert py[0]['id']!=py[1]['id']and json.loads(json.dumps(py))==py
    node=shutil.which('node')
    if not node:raise RuntimeError('Existing Node executable required; do not install for this exercise')
    p=subprocess.run([node,'-e',JS],input=json.dumps({'raw':raw,'strings':strings}),capture_output=True,text=True,encoding='utf-8',timeout=15,check=True);out=json.loads(p.stdout)
    assert out['numbers_equal']and out['numbers']==[9007199254740992,9007199254740992]
    assert out['from_rounded_number_bigint']=='9007199254740992'and out['from_original_digits_bigint']=='9007199254740993'
    assert not out['strings_equal']and out['strings']==['9007199254740992','9007199254740993']
    assert json.loads(out['serialized'])!=py and json.loads(out['strings_serialized'])==json.loads(strings)
    return {'python_version':sys.version.split()[0],'authored_raw_json':raw,'python_parsed':py,'python_types':[type(x['id']).__name__ for x in py],'python_serialized':json.dumps(py,separators=(',',':')),'authored_string_contract_json':strings,'node_actual_result':out,'scope':'Actual existing Python and Node parse raw JSON strings. No context.source/reviver feature claim or new dependency. Specific binary64 collision does not mean all integers above2^53 unrepresentable or invalid JSON. Identifier strings are explicit contract choice, not a rule to stringify every price/math value. No customer IDs used.'}
if __name__=='__main__':print(json.dumps(demo(),ensure_ascii=False,indent=2))
