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 listApr 21, 2026 10:27limanjun99limanjun99Error
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 00:58Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 01:00042,030,51923,420,0008,584,00094,392,320invalid character '<' after object key:value pair
2Jul 6, 2026 01:00042,061,84823,339,0008,630,00094,392,320invalid character '<' after object key:value pair
3Jul 6, 2026 01:00041,669,15523,255,0008,790,00094,392,320invalid character '<' after object key:value pair
4Apr 21, 2026 10:293,75954,848,60925,155,0009,056,00092,962,816
5Apr 21, 2026 10:293,75956,583,94524,151,00010,062,00093,196,288
6Apr 21, 2026 10:293,76362,501,41626,192,0008,059,00092,835,840
7Apr 21, 2026 10:293,76654,625,95124,193,00010,080,00093,147,136
8Apr 21, 2026 10:293,76957,649,55024,215,00010,089,00092,880,896
9Apr 21, 2026 10:293,77159,581,13724,229,00010,095,00093,179,904
10Apr 21, 2026 10:293,77656,526,65127,291,0007,075,00093,159,424
11Apr 21, 2026 10:293,78556,475,98024,318,00010,132,00092,876,800
12Apr 21, 2026 10:293,78767,581,74726,359,0008,110,00092,893,184