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 02:58Joad NacerJoad NacerScore: 4,349Success
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 02:583,93962,447,29324,891,00010,952,00092,950,528
2Apr 22, 2024 02:583,95160,747,70924,968,00010,986,00092,921,856
3Apr 22, 2024 02:583,96265,539,22125,037,00011,016,00092,917,760
4Apr 22, 2024 02:583,96263,911,92126,039,00010,015,00092,897,280
5Apr 22, 2024 02:583,99559,052,51825,248,00011,109,00092,839,936
6Apr 22, 2024 02:584,33499,745,95539,441,342094,482,432
7Apr 22, 2024 02:584,349103,517,12939,573,886094,486,528
8Apr 22, 2024 02:584,357107,571,11739,647,203094,486,528
9Apr 22, 2024 02:586,20281,469,86527,211,00029,226,00093,073,408
10Apr 22, 2024 02:586,45986,239,40926,898,00031,880,00093,081,600
11Apr 22, 2024 02:586,73687,603,67927,130,00034,164,00093,220,864
12Apr 22, 2024 02:587,80599,369,12329,012,00042,018,00093,368,320