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 28, 2026 02:53Charles CabergsCharles CabergsError
Source Code

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

Challenge History
DateChallengerCostTypeStatus
Jul 6, 2026 09:04Victor Mercklé10.00CustomSolution Broken
Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 6, 2026 09:05012,019,55502,171,0002,121,728invalid character '<' after object key:value pair
2Jul 6, 2026 09:05011,938,01902,165,0002,121,728invalid character '<' after object key:value pair
3Jul 6, 2026 09:05011,927,22602,166,0002,121,728invalid character '<' after object key:value pair
4Apr 28, 2026 02:554,20556,940,08020,143,00018,129,00094,609,408
5Apr 28, 2026 02:554,20655,974,12921,153,00017,124,00094,609,408
6Apr 28, 2026 02:554,23457,193,49419,763,00018,775,00094,801,920
7Apr 28, 2026 02:554,24255,025,71019,798,00018,808,00094,797,824
8Apr 28, 2026 02:554,24658,555,13718,824,00019,815,00094,609,408
9Apr 28, 2026 02:554,24857,476,58120,816,00017,842,00094,801,920
10Apr 28, 2026 02:554,25055,683,61617,854,00020,830,00094,801,920
11Apr 28, 2026 02:554,27162,190,56121,926,00016,942,00094,797,824
12Apr 28, 2026 02:554,27559,006,87120,952,00017,959,00094,785,536