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:29Joad NacerJoad NacerScore: 3,870Success
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:293,62756,391,60623,005,00010,002,00092,938,240
2May 22, 2024 00:293,63062,843,72022,021,00011,010,00092,934,144
3May 22, 2024 00:293,69863,724,55722,763,00010,887,00093,097,984
4May 22, 2024 00:293,71558,876,82321,873,00011,931,00092,893,184
5May 22, 2024 00:293,84992,726,18535,028,190094,482,432
6May 22, 2024 00:293,869101,266,71035,208,239094,617,600
7May 22, 2024 00:293,87088,251,17735,215,875094,486,528
8May 22, 2024 00:294,12362,772,41523,322,00014,196,00093,089,792
9May 22, 2024 00:294,35264,978,50922,342,00017,264,00093,159,424
10May 22, 2024 00:297,67199,903,12025,928,00043,879,00093,212,672
11May 22, 2024 00:297,67195,144,47227,924,00041,886,00093,323,264
12May 22, 2024 00:297,68798,397,15825,981,00043,969,00093,282,304