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 21, 2024 21:47Joad NacerJoad NacerScore: 3,832Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 21, 2024 21:473,62357,862,75721,981,00010,990,00092,860,416
2May 21, 2024 21:473,68565,112,36622,358,00011,179,00092,856,320
3May 21, 2024 21:473,70367,670,82422,794,00010,901,00092,934,144
4May 21, 2024 21:473,70959,604,16322,834,00010,920,00093,073,408
5May 21, 2024 21:473,71559,077,54621,875,00011,932,00092,893,184
6May 21, 2024 21:473,825102,560,16734,805,635094,740,480
7May 21, 2024 21:473,83299,746,54334,871,819094,605,312
8May 21, 2024 21:473,83595,851,92234,896,501094,482,432
9May 21, 2024 21:474,54670,429,35023,206,00018,161,00093,102,080
10May 21, 2024 21:475,62884,385,03423,636,00027,576,00093,024,256
11May 21, 2024 21:477,18395,314,69326,144,00039,217,00093,102,080
12May 21, 2024 21:477,69993,463,89927,022,00043,035,00093,184,000