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 01:22Joad NacerJoad NacerScore: 4,624Success
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 01:223,43452,740,54220,161,00011,088,00092,848,128
2May 22, 2024 01:223,45857,555,93321,317,00010,151,00092,921,856
3May 22, 2024 01:223,52257,626,62120,030,00012,018,00092,876,800
4May 22, 2024 01:223,654101,753,70533,253,800094,621,696
5May 22, 2024 01:223,661102,995,43933,314,207094,482,432
6May 22, 2024 01:223,66996,736,56033,391,621094,744,576
7May 22, 2024 01:224,62468,060,41922,039,00020,035,00093,114,368
8May 22, 2024 01:224,99174,924,40423,215,00022,206,00093,073,408
9May 22, 2024 01:225,59577,557,94023,958,00026,953,00093,044,736
10May 22, 2024 01:227,51893,035,47625,152,00043,262,00093,302,784
11May 22, 2024 01:227,55798,333,97825,912,00042,856,00093,265,920
12May 22, 2024 01:227,60296,620,69725,066,00044,116,00093,229,056