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 30, 2026 05:09Charles CabergsCharles CabergsError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 01:30Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 01:31011,321,76201,976,0002,121,728invalid character '<' after object key:value pair
2Jul 6, 2026 01:31011,249,36001,793,0002,121,728invalid character '<' after object key:value pair
3Jul 6, 2026 01:31014,392,15101,964,0002,121,728invalid character '<' after object key:value pair
4Apr 30, 2026 05:123,98760,493,84518,145,00018,145,00094,605,312
5Apr 30, 2026 05:124,00350,893,96919,227,00017,203,00094,617,600
6Apr 30, 2026 05:124,00356,597,92520,239,00016,191,00094,793,728
7Apr 30, 2026 05:124,00755,311,02416,208,00020,260,00094,806,016
8Apr 30, 2026 05:124,00752,429,65718,236,00018,236,00094,793,728
9Apr 30, 2026 05:124,01455,484,99519,280,00017,250,00094,797,824
10Apr 30, 2026 05:124,01456,906,45718,760,00017,772,00094,801,920
11Apr 30, 2026 05:124,02153,569,46318,791,00017,802,00094,793,728
12Apr 30, 2026 05:124,03552,944,56217,864,00018,856,00094,801,920