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:04Sergey StreminSergey StreminScore: 6,245Success
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:045,57978,057,66232,850,00017,918,00094,715,904
2May 26, 2021 18:045,639122,534,61351,314,081094,801,920
3May 26, 2021 18:045,84179,518,03141,119,00012,034,00094,707,712
4May 26, 2021 18:045,85276,043,78939,186,00014,067,00092,983,296
5May 26, 2021 18:045,886115,569,07953,566,272094,662,656
6May 26, 2021 18:046,16678,305,59441,083,00015,030,00094,707,712
7May 26, 2021 18:046,245128,738,11356,833,323094,662,656
8May 26, 2021 18:046,29178,467,53943,187,00014,061,00094,560,256
9May 26, 2021 18:046,32186,365,12935,321,00022,202,00094,707,712
10May 26, 2021 18:046,39477,425,61938,123,00020,065,00093,253,632
11May 26, 2021 18:046,41381,327,64739,239,00019,116,00094,720,000
12May 26, 2021 18:046,46883,406,26037,911,00020,950,00093,143,040