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 listApr 21, 2024 23:39Joad NacerJoad NacerScore: 4,036Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:393,93461,055,96325,858,0009,945,00092,876,800
2Apr 21, 2024 23:393,96765,450,45325,071,00011,031,00092,880,896
3Apr 21, 2024 23:394,01162,668,03325,349,00011,153,00092,921,856
4Apr 21, 2024 23:394,01363,378,97525,360,00011,158,00092,876,800
5Apr 21, 2024 23:394,01362,979,92626,376,00010,144,00092,893,184
6Apr 21, 2024 23:394,03564,406,21125,802,00010,916,00092,868,608
7Apr 21, 2024 23:394,03662,565,77724,814,00011,910,00092,868,608
8Apr 21, 2024 23:394,179107,325,22138,026,861094,490,624
9Apr 21, 2024 23:394,191103,679,82238,133,661094,486,528
10Apr 21, 2024 23:394,207101,906,23438,286,442094,490,624
11Apr 21, 2024 23:395,13777,396,30026,857,00019,894,00093,200,384
12Apr 21, 2024 23:395,72177,613,61927,033,00025,031,00093,130,752