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:54Ilya AniskovetsIlya AniskovetsScore: 10,004Success
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:549,587147,171,48387,237,428094,674,944
2Oct 31, 2021 13:549,591154,377,22487,275,159094,756,864
3Oct 31, 2021 13:549,609143,601,47187,445,091094,789,632
4Oct 31, 2021 13:549,976117,241,76043,893,00046,886,00094,593,024
5Oct 31, 2021 13:549,984118,951,17845,926,00044,928,00094,576,640
6Oct 31, 2021 13:549,991111,626,76844,959,00045,958,00094,617,600
7Oct 31, 2021 13:5410,004112,676,16943,019,00048,021,00094,552,064
8Oct 31, 2021 13:5410,015114,574,09048,072,00043,065,00094,597,120
9Oct 31, 2021 13:5410,028112,726,55340,113,00051,144,00094,584,832
10Oct 31, 2021 13:5410,031115,095,67739,120,00052,161,00094,666,752
11Oct 31, 2021 13:5410,187118,436,16446,848,00045,851,00092,983,296
12Oct 31, 2021 13:5410,311116,955,49937,930,00055,898,00093,069,312