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 9, 2024 23:16Joad NacerJoad NacerScore: 4,105Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:163,89661,983,94525,326,00010,130,00092,942,336
2May 9, 2024 23:163,90165,682,50325,359,00010,143,00092,954,624
3May 9, 2024 23:163,93566,024,63423,874,00011,937,00092,868,608
4May 9, 2024 23:163,93761,723,68824,881,00010,948,00092,921,856
5May 9, 2024 23:163,94062,752,33423,900,00011,950,00092,942,336
6May 9, 2024 23:163,95762,498,67624,008,00012,004,00092,880,896
7May 9, 2024 23:164,10599,710,61037,358,974094,478,336
8May 9, 2024 23:164,113110,507,10337,429,531094,486,528
9May 9, 2024 23:164,122104,424,22937,511,812094,494,720
10May 9, 2024 23:167,27397,362,21428,078,00038,107,00093,270,016
11May 9, 2024 23:167,29887,489,66329,181,00037,231,00093,093,888
12May 9, 2024 23:167,763101,190,58928,259,00042,388,00093,241,344