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 13:39Ilya AniskovetsIlya AniskovetsScore: 10,304Success
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 13:399,834145,217,74489,487,569094,699,520
2Oct 31, 2021 13:399,863145,306,13389,749,942094,687,232
3Oct 31, 2021 13:399,864142,521,22489,763,571094,691,328
4Oct 31, 2021 13:3910,265119,112,37552,232,00041,183,00094,740,480
5Oct 31, 2021 13:3910,288123,779,23939,840,00053,785,00094,691,328
6Oct 31, 2021 13:3910,300116,674,65137,890,00055,838,00094,662,656
7Oct 31, 2021 13:3910,304115,559,59852,866,00040,896,00092,938,240
8Oct 31, 2021 13:3910,314116,937,05042,934,00050,922,00094,654,464
9Oct 31, 2021 13:3910,322118,686,54943,968,00049,964,00094,728,192
10Oct 31, 2021 13:3910,326123,779,48847,981,00045,982,00094,711,808
11Oct 31, 2021 13:3910,697118,210,31444,156,00053,188,00093,179,904
12Oct 31, 2021 13:3910,776124,556,94446,029,00052,033,00093,118,464