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 listMar 10, 2026 16:22Josu San MartinJosu San MartinError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 08:13Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 08:14010,525,06301,378,0002,121,728invalid character '\n' in string literal
2Jul 6, 2026 08:14010,530,56701,345,0002,121,728invalid character '\n' in string literal
3Jul 6, 2026 08:14010,445,3141,181,00002,121,728invalid character '\n' in string literal
4Mar 10, 2026 16:224,04570,299,95118,902,00017,907,00094,732,288
5Mar 10, 2026 16:224,05261,177,59416,942,00019,931,00094,674,944
6Mar 10, 2026 16:224,05759,910,67519,958,00016,964,00094,785,536
7Mar 10, 2026 16:224,05858,739,25117,965,00018,964,00094,552,064
8Mar 10, 2026 16:224,06158,779,30720,976,00015,981,00094,785,536
9Mar 10, 2026 16:224,06661,156,97719,003,00018,002,00094,547,968
10Mar 10, 2026 16:224,06860,703,65220,010,00017,009,00094,674,944
11Mar 10, 2026 16:224,08559,685,37718,083,00019,088,00094,552,064
12Mar 10, 2026 16:224,09366,537,36520,134,00017,114,00094,670,848