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 listSep 16, 2026 16:24Victor MerckléVictor MerckléScore: 2,605Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 16, 2026 16:302,59332,315,00214,930,0008,669,00092,762,112stderr
2Sep 16, 2026 16:302,59733,790,94014,943,0008,691,00092,725,248stderr
3Sep 16, 2026 16:302,60432,431,30414,957,0008,748,00092,762,112stderr
4Sep 16, 2026 16:302,60434,658,53815,011,0008,687,00092,704,768stderr
5Sep 16, 2026 16:302,60532,402,32515,003,0008,704,00092,794,880stderr
6Sep 16, 2026 16:302,60833,159,41115,241,0008,499,00092,729,344stderr
7Sep 16, 2026 16:302,61732,556,60115,252,0008,565,00092,758,016stderr
8Sep 16, 2026 16:302,61833,306,20515,245,0008,586,00092,663,808stderr
9Sep 16, 2026 16:302,62032,570,04515,159,0008,686,00092,708,864stderr