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 listMay 9, 2024 23:34Joad NacerJoad NacerScore: 3,880Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:343,64460,358,92923,111,00010,048,00092,925,952
2May 9, 2024 23:343,68063,817,11222,327,00011,163,00092,958,720
3May 9, 2024 23:343,69259,687,77222,400,00011,200,00092,930,048
4May 9, 2024 23:343,71161,711,21421,851,00011,918,00092,925,952
5May 9, 2024 23:343,71960,981,96121,900,00011,945,00092,893,184
6May 9, 2024 23:343,72061,383,70721,903,00011,947,00093,110,272
7May 9, 2024 23:343,88098,873,57835,304,137094,601,216
8May 9, 2024 23:343,886103,835,56435,364,950094,482,432
9May 9, 2024 23:343,890106,566,23535,398,715094,486,528
10May 9, 2024 23:345,81377,297,40024,952,00027,946,00093,069,312
11May 9, 2024 23:345,88976,475,36925,279,00028,312,00093,171,712
12May 9, 2024 23:346,91191,209,49826,952,00035,937,00093,278,208