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 09:45Victor MerckléVictor MerckléScore: 2,664Success
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 09:512,65432,419,84315,452,0008,705,00092,790,784stderr
2Jul 1, 2026 09:512,65432,471,84615,411,0008,744,00092,684,288stderr
3Jul 1, 2026 09:512,66031,973,55615,475,0008,732,00092,778,496stderr
4Jul 1, 2026 09:512,66332,149,24415,545,0008,692,00092,725,248stderr
5Jul 1, 2026 09:512,66432,109,21415,508,0008,739,00092,782,592stderr
6Jul 1, 2026 09:512,66932,428,07515,535,0008,757,00092,704,768stderr
7Jul 1, 2026 09:512,67032,424,40715,529,0008,774,00092,741,632stderr
8Jul 1, 2026 09:512,67832,173,87315,574,0008,796,00092,700,672stderr
9Jul 1, 2026 09:512,69532,386,59515,655,0008,873,00092,753,920stderr