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 4, 2026 10:22Victor MerckléVictor MerckléScore: 2,370Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 4, 2026 10:312,36030,516,67112,834,0008,643,00092,774,400stderr
2Sep 4, 2026 10:312,36330,448,81613,023,0008,489,00092,770,304stderr
3Sep 4, 2026 10:312,36630,569,07113,016,0008,518,00092,725,248stderr
4Sep 4, 2026 10:312,36930,488,96413,061,0008,498,00092,729,344stderr
5Sep 4, 2026 10:312,37030,787,96113,043,0008,524,00092,688,384stderr
6Sep 4, 2026 10:312,37330,639,09713,052,0008,546,00092,725,248stderr
7Sep 4, 2026 10:312,38530,825,20213,102,0008,606,00092,749,824stderr
8Sep 4, 2026 10:312,38730,684,02313,095,0008,634,00092,782,592stderr
9Sep 4, 2026 10:312,39130,789,28713,014,0008,749,00092,721,152stderr