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:40Ilya AniskovetsIlya AniskovetsScore: 10,295Success
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:409,869148,134,71089,807,918094,732,288
2Oct 31, 2021 13:409,880148,435,03189,908,459094,703,616
3Oct 31, 2021 13:409,918150,705,10390,253,526094,711,808
4Oct 31, 2021 13:4010,262124,898,56141,170,00052,216,00094,720,000
5Oct 31, 2021 13:4010,289120,288,12341,835,00051,796,00094,687,232
6Oct 31, 2021 13:4010,292120,496,50552,807,00040,850,00094,740,480
7Oct 31, 2021 13:4010,295121,512,14945,847,00047,841,00094,679,040
8Oct 31, 2021 13:4010,303120,292,44848,872,00044,882,00094,707,712
9Oct 31, 2021 13:4010,320116,807,85446,956,00046,956,00094,556,160
10Oct 31, 2021 13:4010,329122,182,44649,997,00043,997,00094,736,384
11Oct 31, 2021 13:4010,409120,418,50647,862,00046,864,00093,220,864
12Oct 31, 2021 13:4010,708126,737,01249,222,00048,217,00093,126,656