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 26, 2026 20:21Kevin HeaveyKevin HeaveyScore: 2,364Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 26, 2026 20:292,35030,160,85412,856,0008,530,00092,762,112
2Sep 26, 2026 20:292,35330,288,51412,940,0008,475,00092,766,208
3Sep 26, 2026 20:292,35630,209,54612,944,0008,501,00092,762,112
4Sep 26, 2026 20:292,36230,323,15813,038,0008,459,00092,762,112
5Sep 26, 2026 20:292,36430,152,14013,026,0008,490,00092,745,728
6Sep 26, 2026 20:292,36831,837,95913,047,0008,504,00092,721,152
7Sep 26, 2026 20:292,37030,350,98513,084,0008,486,00092,749,824
8Sep 26, 2026 20:292,37730,429,32813,076,0008,559,00092,729,344
9Sep 26, 2026 20:292,37930,435,31413,088,0008,568,00092,684,288