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 4, 2026 08:33Victor MerckléVictor MerckléScore: 2,707Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 4, 2026 08:412,69532,928,47615,861,0008,665,00092,766,208stderr
2Sep 4, 2026 08:412,69632,905,62215,810,0008,728,00092,803,072stderr
3Sep 4, 2026 08:412,70133,002,93315,870,0008,718,00092,733,440stderr
4Sep 4, 2026 08:412,70433,000,57016,031,0008,584,00092,741,632stderr
5Sep 4, 2026 08:412,70733,640,76415,996,0008,640,00092,753,920stderr
6Sep 4, 2026 08:412,71433,676,56015,939,0008,764,00092,667,904stderr
7Sep 4, 2026 08:412,71633,153,94815,908,0008,813,00092,782,592stderr
8Sep 4, 2026 08:412,71733,074,36815,939,0008,789,00092,774,400stderr
9Sep 4, 2026 08:412,73733,961,22016,180,0008,734,00092,758,016stderr