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 17, 2026 13:17Victor MerckléVictor MerckléScore: 2,580Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 17, 2026 13:292,56532,110,67414,823,0008,524,00092,725,248stderr
2Sep 17, 2026 13:292,57332,184,55314,860,0008,557,00092,692,480stderr
3Sep 17, 2026 13:292,57532,230,68814,808,0008,627,00092,778,496stderr
4Sep 17, 2026 13:292,57932,305,00014,849,0008,627,00092,688,384stderr
5Sep 17, 2026 13:292,58032,259,36514,809,0008,677,00092,700,672stderr
6Sep 17, 2026 13:292,58432,282,65214,925,0008,597,00092,737,536stderr
7Sep 17, 2026 13:292,59341,514,42714,846,0008,751,00092,704,768stderr
8Sep 17, 2026 13:292,59733,007,95514,945,0008,696,00092,778,496stderr
9Sep 17, 2026 13:292,59932,449,30114,988,0008,670,00092,741,632stderr