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 listJul 1, 2026 10:33Victor MerckléVictor MerckléScore: 3,045Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 1, 2026 10:393,03036,850,52517,927,0009,653,00092,712,960stderr
2Jul 1, 2026 10:393,03336,929,05517,988,0009,614,00092,758,016stderr
3Jul 1, 2026 10:393,03436,930,84517,943,0009,669,00092,717,056stderr
4Jul 1, 2026 10:393,04136,972,02818,006,0009,676,00092,696,576stderr
5Jul 1, 2026 10:393,04537,039,55617,978,0009,733,00092,688,384stderr
6Jul 1, 2026 10:393,04937,093,26018,027,0009,727,00092,704,768stderr
7Jul 1, 2026 10:393,05337,116,29618,064,0009,725,00092,741,632stderr
8Jul 1, 2026 10:393,05937,137,01818,057,0009,786,00092,712,960stderr
9Jul 1, 2026 10:393,07237,296,94118,060,0009,897,00092,745,728stderr