XML to JSON Sergey Svistunov

Convert 1,000,000 person records from XML to JSON as fast as possible.

Input

XML document on STDIN:

<?xml version="1.0" encoding="UTF-8"?>
<persons>
    <person id="1512376">
        <age>30</age>
        <height>169.1</height>
        <married>true</married>
        <phone code="+6"><number>1283603279</number></phone>
        <phone code="+6"><number>1659964668</number></phone>
    </person>
    ...
</persons>

Output

One JSON object per person to STDOUT, preserving order:

{
    "id": 1512376,
    "age": 30,
    "height": 169.1,
    "married": true,
    "phones": [
        {
            "code": "+6",
            "number": 1283603279
        },
        {
            "code": "+6",
            "number": 1659964668
        }
    ]
}

Constraints

  • Preserve the order of persons
  • Omit the phones field if the phone array is empty
  • Maximum number of phones per person is 3
Back to listAug 19, 2026 10:27Victor MerckléVictor MerckléScore: 2,582Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Aug 19, 2026 10:332,55731,660,07014,841,0008,434,00092,733,440stderr
2Aug 19, 2026 10:332,56932,591,41114,877,0008,503,00092,762,112stderr
3Aug 19, 2026 10:332,57432,424,57014,764,0008,664,00092,762,112stderr
4Aug 19, 2026 10:332,57532,455,93814,670,0008,765,00092,737,536stderr
5Aug 19, 2026 10:332,58232,727,46914,682,0008,817,00092,704,768stderr
6Aug 19, 2026 10:332,58531,844,05414,660,0008,871,00092,790,784stderr
7Aug 19, 2026 10:332,59132,588,14515,036,0008,548,00092,782,592stderr
8Aug 19, 2026 10:332,59732,697,04814,741,0008,897,00092,717,056stderr
9Aug 19, 2026 10:332,61232,058,85215,005,0008,771,00092,741,632stderr