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 22, 2024 03:02Joad NacerJoad NacerScore: 4,981Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 03:023,81768,008,64223,820,00010,917,00092,811,264
2Apr 22, 2024 03:023,82660,929,31322,881,00011,938,00093,106,176
3Apr 22, 2024 03:023,86369,617,82123,102,00012,053,00092,962,816
4Apr 22, 2024 03:024,013114,306,14436,522,231094,654,464
5Apr 22, 2024 03:024,023105,253,88936,604,890094,490,624
6Apr 22, 2024 03:024,117100,371,42237,463,286094,613,504
7Apr 22, 2024 03:024,98173,725,44226,189,00019,138,00093,044,736
8Apr 22, 2024 03:025,15371,984,75424,944,00021,951,00093,102,080
9Apr 22, 2024 03:025,83779,257,15225,055,00028,062,00093,052,928
10Apr 22, 2024 03:026,98790,455,96727,251,00036,335,00093,175,808
11Apr 22, 2024 03:027,865103,708,89228,225,00043,345,00093,270,016
12Apr 22, 2024 03:027,895101,244,64228,936,00042,905,00093,274,112