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 22, 2024 00:05Joad NacerJoad NacerScore: 3,972Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 00:053,64054,522,26622,084,00011,042,00092,909,568
2May 22, 2024 00:053,69162,120,77823,413,00010,179,00092,905,472
3May 22, 2024 00:053,70761,262,70821,829,00011,906,00092,852,224
4May 22, 2024 00:053,72764,179,67721,947,00011,971,00092,913,664
5May 22, 2024 00:053,929111,646,31135,751,172094,613,504
6May 22, 2024 00:053,953107,202,32235,973,823094,486,528
7May 22, 2024 00:053,972104,835,45736,145,517094,621,696
8May 22, 2024 00:055,27675,761,07524,006,00024,006,00093,118,464
9May 22, 2024 00:055,80280,664,91126,895,00025,899,00093,114,368
10May 22, 2024 00:056,30788,027,40925,171,00032,219,00093,265,920
11May 22, 2024 00:057,27791,201,32526,087,00040,134,00093,327,360
12May 22, 2024 00:057,776104,418,70827,906,00042,856,00093,253,632