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 21, 2024 21:49Joad NacerJoad NacerScore: 3,765Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 21, 2024 21:493,54061,495,82521,142,00011,074,00092,925,952
2May 21, 2024 21:493,54154,590,48622,151,00010,068,00092,934,144
3May 21, 2024 21:493,55956,939,98021,255,00011,134,00092,876,800
4May 21, 2024 21:493,56459,031,47323,312,0009,122,00092,930,048
5May 21, 2024 21:493,61059,038,36721,899,00010,949,00092,868,608
6May 21, 2024 21:493,64055,425,83821,078,00012,045,00092,938,240
7May 21, 2024 21:493,765100,202,79534,265,208094,486,528
8May 21, 2024 21:493,77488,890,32934,342,707094,486,528
9May 21, 2024 21:493,790119,916,87534,488,890094,486,528
10May 21, 2024 21:495,85776,578,66824,134,00029,163,00093,147,136
11May 21, 2024 21:496,98390,038,13626,225,00037,321,00093,270,016
12May 21, 2024 21:497,09995,340,93025,235,00039,366,00093,179,904