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 23:24Joad NacerJoad NacerScore: 3,866Success
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 23:243,59161,356,04621,786,00010,893,00092,930,048
2May 21, 2024 23:243,62158,639,85922,963,0009,984,00093,016,064
3May 21, 2024 23:243,64360,006,75221,099,00012,056,00092,930,048
4May 21, 2024 23:243,65355,523,04121,154,00012,088,00092,893,184
5May 21, 2024 23:243,824113,144,62134,796,059094,498,816
6May 21, 2024 23:243,86099,497,79935,125,492094,494,720
7May 21, 2024 23:243,86696,947,82435,180,454094,498,816
8May 21, 2024 23:245,24973,050,53122,889,00024,880,00093,048,832
9May 21, 2024 23:246,12677,401,28326,879,00028,870,00093,020,160
10May 21, 2024 23:247,34195,981,76325,925,00040,882,00093,208,576
11May 21, 2024 23:247,59494,083,25126,040,00043,067,00093,196,288
12May 21, 2024 23:247,59892,626,49728,058,00041,085,00093,212,672