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 15:42Victor MerckléVictor MerckléScore: 2,371Success
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 15:542,34829,772,06112,899,0008,473,00092,741,632stderr
2Sep 4, 2026 15:542,35631,074,05912,952,0008,490,00092,807,168stderr
3Sep 4, 2026 15:542,36729,921,78613,029,0008,519,00092,831,744stderr
4Sep 4, 2026 15:542,37029,871,09213,066,0008,510,00092,737,536stderr
5Sep 4, 2026 15:542,37130,633,93313,072,0008,508,00092,803,072stderr
6Sep 4, 2026 15:542,37430,634,56713,090,0008,515,00092,758,016stderr
7Sep 4, 2026 15:542,37930,680,11013,060,0008,590,00092,741,632stderr
8Sep 4, 2026 15:542,38130,035,86313,067,0008,603,00092,770,304stderr
9Sep 4, 2026 15:542,39331,372,75113,176,0008,601,00092,672,000stderr