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 10, 2024 00:49Joad NacerJoad NacerScore: 3,776Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 10, 2024 00:493,53661,721,68921,117,00011,061,00092,921,856
2May 10, 2024 00:493,54959,160,02221,193,00011,101,00092,897,280
3May 10, 2024 00:493,57160,554,81322,338,00010,154,00092,942,336
4May 10, 2024 00:493,58958,487,69220,781,00011,875,00092,864,512
5May 10, 2024 00:493,63265,408,15521,033,00012,019,00092,909,568
6May 10, 2024 00:493,762107,367,56534,233,757094,486,528
7May 10, 2024 00:493,77693,082,78434,364,870094,613,504
8May 10, 2024 00:493,803114,944,44934,606,754094,490,624
9May 10, 2024 00:495,72176,021,72923,027,00029,034,00093,126,656
10May 10, 2024 00:496,15785,982,51224,014,00032,019,00093,306,880
11May 10, 2024 00:496,77393,471,70625,260,00036,374,00093,233,152
12May 10, 2024 00:497,650104,452,30926,231,00043,383,00093,270,016