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 listJul 1, 2026 10:14Victor MerckléVictor MerckléScore: 2,710Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 1, 2026 10:202,68133,958,77915,710,0008,693,00092,782,592stderr
2Jul 1, 2026 10:202,70533,972,82415,817,0008,805,00092,700,672stderr
3Jul 1, 2026 10:202,70534,038,27215,794,0008,823,00092,737,536stderr
4Jul 1, 2026 10:202,70633,979,65615,826,0008,806,00092,766,208stderr
5Jul 1, 2026 10:202,71034,005,26415,861,0008,804,00092,753,920stderr
6Jul 1, 2026 10:202,71834,051,71215,875,0008,859,00092,749,824stderr
7Jul 1, 2026 10:202,73534,197,69815,950,0008,943,00092,782,592stderr
8Jul 1, 2026 10:202,73634,180,22315,958,0008,948,00092,807,168stderr
9Jul 1, 2026 10:202,73734,206,77815,994,0008,918,00092,729,344stderr