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:20Joad NacerJoad NacerScore: 3,652Success
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:203,41757,229,15920,064,00011,035,00092,938,240
2May 21, 2024 23:203,45256,994,55221,280,00010,133,00092,930,048
3May 21, 2024 23:203,46761,098,96221,371,00010,176,00092,954,624
4May 21, 2024 23:203,48059,267,69221,774,0009,897,00093,126,656
5May 21, 2024 23:203,50163,253,85919,914,00011,948,00092,925,952
6May 21, 2024 23:203,53453,863,06620,097,00012,058,00092,995,584
7May 21, 2024 23:203,65297,838,76533,232,989094,490,624
8May 21, 2024 23:203,66295,877,13033,324,820094,486,528
9May 21, 2024 23:203,684114,963,30033,526,686094,498,816
10May 21, 2024 23:205,90278,522,45124,865,00028,844,00093,122,560
11May 21, 2024 23:206,08179,092,30323,139,00032,194,00092,995,584
12May 21, 2024 23:206,93387,599,01324,035,00039,057,00093,097,984