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 14:00Ilya AniskovetsIlya AniskovetsScore: 10,340Success
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 14:0010,031156,343,41591,283,603094,793,728
2Oct 31, 2021 14:0010,041155,410,18691,370,594094,773,248
3Oct 31, 2021 14:0010,076164,958,49791,695,066094,674,944
4Oct 31, 2021 14:0010,300121,113,54843,874,00049,856,00094,699,520
5Oct 31, 2021 14:0010,320123,895,58942,960,00050,952,00094,691,328
6Oct 31, 2021 14:0010,337118,880,66353,036,00041,028,00094,756,864
7Oct 31, 2021 14:0010,340114,177,38149,051,00045,047,00094,744,576
8Oct 31, 2021 14:0010,349119,624,53548,091,00046,087,00094,695,424
9Oct 31, 2021 14:0010,355116,922,33646,112,00048,117,00094,654,464
10Oct 31, 2021 14:0010,364117,640,41347,155,00047,155,00094,732,288
11Oct 31, 2021 14:0010,376121,135,45143,192,00051,228,00093,118,464
12Oct 31, 2021 14:0010,378116,597,09544,207,00050,235,00094,670,848