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 listApr 21, 2024 23:51Joad NacerJoad NacerScore: 4,284Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:513,99167,189,46925,218,00011,096,00092,942,336
2Apr 21, 2024 23:514,01563,029,75126,386,00010,148,00092,848,128
3Apr 21, 2024 23:514,03964,141,98625,830,00010,928,00092,917,760
4Apr 21, 2024 23:514,04363,446,54124,860,00011,932,00092,950,528
5Apr 21, 2024 23:514,05361,276,10025,917,00010,965,00092,913,664
6Apr 21, 2024 23:514,06361,472,40124,981,00011,990,00092,917,760
7Apr 21, 2024 23:514,284107,658,23538,982,052094,486,528
8Apr 21, 2024 23:514,284104,765,45238,983,959094,490,624
9Apr 21, 2024 23:514,303101,563,75839,161,170094,494,720
10Apr 21, 2024 23:514,41467,218,17625,104,00015,062,00092,897,280
11Apr 21, 2024 23:515,68375,815,67627,847,00023,869,00093,179,904
12Apr 21, 2024 23:515,69778,785,78327,916,00023,928,00093,138,944