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 09:51Victor MerckléVictor MerckléScore: 4,206Success
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 09:534,18754,109,40120,057,00018,051,00094,773,248
2May 1, 2026 09:534,19653,694,78621,102,00017,083,00094,781,440
3May 1, 2026 09:534,20155,401,31422,133,00016,097,00094,597,120
4May 1, 2026 09:534,20656,099,18722,160,00016,116,00094,597,120
5May 1, 2026 09:534,20657,536,08422,161,00016,117,00094,773,248
6May 1, 2026 09:534,21254,603,50424,211,00014,123,00094,781,440
7May 1, 2026 09:534,22957,864,35816,207,00022,285,00094,781,440
8May 1, 2026 09:534,23455,751,98122,308,00016,224,00094,781,440
9May 1, 2026 09:534,23655,914,87617,795,00020,761,00094,777,344