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 18, 2026 06:39M-RochatM-RochatError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 11:23Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 11:24058,117,13540,302,0008,412,00092,893,184invalid character '<' after object key:value pair
2Jul 6, 2026 11:24058,048,53840,160,0008,460,00092,893,184invalid character '<' after object key:value pair
3Jul 6, 2026 11:24057,823,00040,152,0008,328,00092,893,184invalid character '<' after object key:value pair
4May 18, 2026 06:535,48659,912,98341,654,0008,277,00092,758,016
5May 18, 2026 06:535,49659,168,97441,701,0008,315,00092,717,056
6May 18, 2026 06:535,49759,742,70341,743,0008,281,00092,758,016
7May 18, 2026 06:535,49859,106,03641,762,0008,274,00092,696,576
8May 18, 2026 06:535,50159,656,95141,663,0008,400,00092,729,344
9May 18, 2026 06:535,50259,105,58741,763,0008,308,00092,762,112
10May 18, 2026 06:535,51160,170,72541,750,0008,404,00092,729,344
11May 18, 2026 06:535,51459,284,77241,792,0008,387,00092,753,920
12May 18, 2026 06:535,51760,370,56841,761,0008,446,00092,745,728