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 listMay 1, 2026 11:17Victor MerckléVictor MerckléScore: 4,126Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 1, 2026 11:194,09960,073,67118,147,00019,155,00094,646,272
2May 1, 2026 11:194,09957,928,59018,147,00019,155,00094,584,832
3May 1, 2026 11:194,10356,273,55819,175,00018,165,00094,650,368
4May 1, 2026 11:194,11753,211,56018,227,00019,239,00094,638,080
5May 1, 2026 11:194,12653,430,24419,766,00017,789,00094,646,272
6May 1, 2026 11:194,12756,204,36119,286,00018,271,00094,580,736
7May 1, 2026 11:194,13155,933,06721,341,00016,260,00094,654,464
8May 1, 2026 11:194,14156,513,94721,817,00015,867,00094,584,832
9May 1, 2026 11:194,15757,827,36119,913,00017,922,00094,642,176