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 listOct 31, 2021 14:10Ilya AniskovetsIlya AniskovetsScore: 11,138Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Oct 31, 2021 14:1010,705135,588,83697,417,561094,740,480
2Oct 31, 2021 14:1010,708155,075,54997,441,018094,769,152
3Oct 31, 2021 14:1010,806173,245,85498,338,601094,715,904
4Oct 31, 2021 14:1011,104128,924,24534,016,00067,033,00093,110,272
5Oct 31, 2021 14:1011,112125,821,23437,044,00064,077,00094,572,544
6Oct 31, 2021 14:1011,135128,668,44235,114,00066,215,00094,785,536
7Oct 31, 2021 14:1011,138127,748,71834,120,00067,236,00094,642,176
8Oct 31, 2021 14:1011,139133,236,38835,126,00066,238,00094,687,232
9Oct 31, 2021 14:1011,167128,681,90334,870,00066,752,00094,752,768
10Oct 31, 2021 14:1011,174129,753,22535,887,00065,793,00094,687,232
11Oct 31, 2021 14:1011,185127,875,34833,929,00067,858,00094,674,944
12Oct 31, 2021 14:1011,692133,705,87435,132,00071,268,00093,114,368