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 26, 2021 18:24Sergey StreminSergey StreminScore: 5,007Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 26, 2021 18:244,86167,137,88330,158,00014,073,00094,707,712
2May 26, 2021 18:244,95577,706,18228,058,00017,035,00094,560,256
3May 26, 2021 18:244,97572,008,83635,214,00010,061,00094,560,256
4May 26, 2021 18:244,991113,031,77745,413,741094,670,848
5May 26, 2021 18:245,00068,812,70331,342,00014,154,00094,707,712
6May 26, 2021 18:245,00172,245,60438,428,0007,078,00094,560,256
7May 26, 2021 18:245,00769,878,99937,465,0008,100,00094,568,448
8May 26, 2021 18:245,03070,780,19627,860,00017,910,00093,151,232
9May 26, 2021 18:245,159123,743,52146,948,003094,666,752
10May 26, 2021 18:245,19870,083,62034,221,00013,084,00093,134,848
11May 26, 2021 18:245,282112,452,20548,067,391094,674,944
12May 26, 2021 18:245,44676,649,32631,354,00018,205,00093,253,632