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 15:22Victor MerckléVictor MerckléScore: 2,548Success
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 15:302,52333,141,33413,859,0009,108,00092,790,784stderr
2Aug 19, 2026 15:302,53433,184,69614,004,0009,062,00092,745,728stderr
3Aug 19, 2026 15:302,53933,195,48614,103,0009,006,00092,717,056stderr
4Aug 19, 2026 15:302,54233,225,09413,916,0009,223,00092,794,880stderr
5Aug 19, 2026 15:302,54832,907,60314,326,0008,867,00092,803,072stderr
6Aug 19, 2026 15:302,54933,279,90214,214,0008,988,00092,827,648stderr
7Aug 19, 2026 15:302,55433,017,93913,991,0009,257,00092,758,016stderr
8Aug 19, 2026 15:302,55533,101,40514,324,0008,934,00092,778,496stderr
9Aug 19, 2026 15:302,55833,513,93114,336,0008,943,00092,762,112stderr