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:01Joad NacerJoad NacerScore: 4,165Success
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:014,02065,283,24526,420,00010,161,00092,905,472
2May 10, 2024 00:014,05073,697,86124,905,00011,954,00092,864,512
3May 10, 2024 00:014,06763,086,89125,004,00012,002,00092,925,952
4May 10, 2024 00:014,08263,377,23126,106,00011,044,00092,880,896
5May 10, 2024 00:014,08359,610,58825,105,00012,050,00092,893,184
6May 10, 2024 00:014,09359,606,78625,167,00012,080,00092,880,896
7May 10, 2024 00:014,16593,669,87637,903,635094,490,624
8May 10, 2024 00:014,17095,943,62037,943,426094,748,672
9May 10, 2024 00:014,19795,152,74238,194,718094,486,528
10May 10, 2024 00:016,33287,108,89528,306,00029,317,00093,085,696
11May 10, 2024 00:016,61785,055,76229,102,00031,109,00093,024,256
12May 10, 2024 00:017,51290,383,75729,154,00039,208,00093,310,976