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 01:00Joad NacerJoad NacerScore: 4,165Success
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 01:003,94663,006,30624,939,00010,973,00092,942,336
2Apr 22, 2024 01:003,95369,924,17424,982,00010,992,00092,909,568
3Apr 22, 2024 01:003,96863,454,15024,072,00012,036,00092,921,856
4Apr 22, 2024 01:003,97558,463,44224,116,00012,058,00092,897,280
5Apr 22, 2024 01:003,97861,656,87725,141,00011,062,00092,975,104
6Apr 22, 2024 01:003,99863,251,02025,264,00011,116,00092,921,856
7Apr 22, 2024 01:004,16589,554,25037,903,116094,494,720
8Apr 22, 2024 01:004,16797,293,05637,920,394094,482,432
9Apr 22, 2024 01:004,173115,078,52537,974,623094,482,432
10Apr 22, 2024 01:004,70873,572,70625,906,00016,938,00093,155,328
11Apr 22, 2024 01:005,14469,045,00325,893,00020,914,00093,163,520
12Apr 22, 2024 01:005,26873,424,14826,964,00020,972,00093,130,752