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:13Sergey StreminSergey StreminScore: 5,448Success
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:135,20869,301,80127,228,00020,169,00094,560,256
2May 26, 2021 18:135,309103,503,21648,314,327094,662,656
3May 26, 2021 18:135,37268,530,27230,926,00017,957,00094,707,712
4May 26, 2021 18:135,37374,796,38234,923,00013,969,00094,715,904
5May 26, 2021 18:135,40174,125,12430,090,00019,057,00094,711,808
6May 26, 2021 18:135,427129,205,40549,387,412094,670,848
7May 26, 2021 18:135,448107,667,03149,579,466094,670,848
8May 26, 2021 18:135,54574,707,77637,342,00013,120,00094,720,000
9May 26, 2021 18:135,71478,269,66933,000,00019,000,00094,560,256
10May 26, 2021 18:135,88277,556,63032,316,00021,207,00093,245,440
11May 26, 2021 18:135,92780,186,73932,962,00020,976,00092,987,392
12May 26, 2021 18:136,08480,894,52742,278,00013,086,00093,253,632