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 17:58Sergey StreminSergey StreminScore: 6,495Success
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 17:586,05676,241,83242,082,00013,025,00094,711,808
2May 26, 2021 17:586,224121,596,27156,642,464094,658,560
3May 26, 2021 17:586,248125,441,71656,852,522094,670,848
4May 26, 2021 17:586,25783,363,57139,959,00016,982,00094,720,000
5May 26, 2021 17:586,30383,498,03643,270,00014,088,00094,560,256
6May 26, 2021 17:586,46286,912,77743,855,00014,950,00094,560,256
7May 26, 2021 17:586,495129,918,76659,106,339094,674,944
8May 26, 2021 17:586,56685,885,94139,835,00019,917,00092,991,488
9May 26, 2021 17:586,61186,306,69446,122,00014,037,00094,552,064
10May 26, 2021 17:586,66384,379,59738,403,00022,233,00093,147,136
11May 26, 2021 17:586,81085,022,06542,979,00018,990,00093,143,040
12May 26, 2021 17:586,84985,629,63745,234,00017,088,00094,543,872