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:41Ilya AniskovetsIlya AniskovetsScore: 9,908Success
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:419,583162,729,59787,205,659094,773,248
2Oct 31, 2021 13:419,595151,139,19287,319,004094,760,960
3Oct 31, 2021 13:419,628156,262,17687,616,439094,785,536
4Oct 31, 2021 13:419,878113,304,80040,949,00048,939,00093,028,352
5Oct 31, 2021 13:419,883119,319,85839,971,00049,964,00094,760,960
6Oct 31, 2021 13:419,900120,739,36542,044,00048,050,00094,580,736
7Oct 31, 2021 13:419,908112,403,52543,076,00047,083,00094,580,736
8Oct 31, 2021 13:419,915111,337,39039,098,00051,129,00094,773,248
9Oct 31, 2021 13:419,919115,101,92541,120,00049,144,00094,744,576
10Oct 31, 2021 13:419,926111,241,52142,152,00048,174,00094,781,440
11Oct 31, 2021 13:4110,164120,542,22748,256,00044,234,00093,204,480
12Oct 31, 2021 13:4110,537121,086,20832,962,00062,928,00093,233,152