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 08:51Joad NacerJoad NacerScore: 3,716Success
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 08:513,45154,968,68520,262,00011,144,00092,868,608
2May 22, 2024 08:513,50359,146,28719,925,00011,955,00092,897,280
3May 22, 2024 08:513,53063,858,62520,076,00012,045,00092,889,088
4May 22, 2024 08:513,66193,327,20133,312,947094,486,528
5May 22, 2024 08:513,66691,679,62433,359,801094,494,720
6May 22, 2024 08:513,67297,053,91633,419,564094,752,768
7May 22, 2024 08:513,71663,768,66420,887,00012,930,00093,200,384
8May 22, 2024 08:515,71979,010,44622,019,00030,026,00093,118,464
9May 22, 2024 08:515,80778,398,46823,928,00028,913,00093,028,352
10May 22, 2024 08:517,50391,397,29625,102,00043,175,00093,298,688
11May 22, 2024 08:517,559102,546,10523,925,00044,860,00093,188,096
12May 22, 2024 08:517,56394,941,93224,934,00043,885,00093,360,128