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 listJul 22, 2023 14:19gchebanovgchebanovScore: 11,121Success
Source Code

Source code access is restricted. Log in to request access.

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 22, 2023 14:1910,479154,870,40195,356,011094,715,904
2Jul 22, 2023 14:1910,631156,200,02696,746,571094,720,000
3Jul 22, 2023 14:1910,802125,687,94685,260,00013,039,00094,564,352
4Jul 22, 2023 14:1910,955125,412,56077,758,00021,931,00094,744,576
5Jul 22, 2023 14:1910,981123,037,03581,937,00017,986,00094,564,352
6Jul 22, 2023 14:1910,991120,734,16583,015,00017,003,00094,744,576
7Jul 22, 2023 14:1911,121176,456,100101,198,375094,707,712
8Jul 22, 2023 14:1911,141126,824,16490,447,00010,933,00094,752,768
9Jul 22, 2023 14:1911,172127,093,56879,736,00021,927,00093,253,632
10Jul 22, 2023 14:1911,205129,571,20086,970,00014,994,00092,995,584
11Jul 22, 2023 14:1911,322129,361,59485,025,00018,005,00093,253,632
12Jul 22, 2023 14:1912,951144,333,522106,869,00010,986,00094,740,480