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:59Ilya AniskovetsIlya AniskovetsScore: 9,790Success
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:599,441147,723,18885,914,725094,785,536
2Oct 31, 2021 13:599,447159,866,44885,965,818094,769,152
3Oct 31, 2021 13:599,491160,026,46986,372,103094,785,536
4Oct 31, 2021 13:599,759111,352,48634,925,00053,885,00094,584,832
5Oct 31, 2021 13:599,768112,924,34235,956,00052,935,00094,572,544
6Oct 31, 2021 13:599,779112,275,20336,997,00051,995,00094,588,928
7Oct 31, 2021 13:599,790119,634,47341,042,00048,049,00094,568,448
8Oct 31, 2021 13:599,796108,022,99438,060,00051,080,00094,683,136
9Oct 31, 2021 13:599,802112,356,48139,529,00049,665,00094,777,344
10Oct 31, 2021 13:599,826122,402,69839,182,00050,233,00094,543,872
11Oct 31, 2021 13:5910,121118,417,88439,042,00053,057,00093,229,056
12Oct 31, 2021 13:5910,236116,829,22442,065,00051,079,00093,216,768