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:36Joad NacerJoad NacerScore: 3,787Success
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:493,53256,781,35821,090,00011,047,00092,913,664
2May 9, 2024 23:363,54759,698,28021,181,00011,094,00093,200,384
3May 9, 2024 23:363,55356,516,85822,231,00010,105,00092,925,952
4May 9, 2024 23:363,59161,775,20321,786,00010,893,00092,925,952
5May 9, 2024 23:493,60361,630,95920,865,00011,922,00092,909,568
6May 9, 2024 23:493,63162,584,88921,026,00012,015,00092,897,280
7May 9, 2024 23:493,63462,203,72621,044,00012,025,00092,880,896
8May 9, 2024 23:363,63561,825,82621,047,00012,027,00092,905,472
9May 9, 2024 23:363,75992,613,73734,203,664094,482,432
10May 9, 2024 23:363,763101,054,70734,242,918094,494,720
11May 9, 2024 23:493,76597,997,47434,264,372094,490,624
12May 9, 2024 23:493,78596,101,73734,444,266094,486,528
13May 9, 2024 23:363,78790,450,03034,461,391094,486,528
14May 9, 2024 23:493,80092,784,73134,578,624094,482,432
15May 9, 2024 23:493,80863,289,12021,785,00012,872,00093,126,656
16May 9, 2024 23:364,05666,732,51521,948,00014,965,00093,089,792
17May 9, 2024 23:494,17064,889,90322,970,00014,980,00093,110,272
18May 9, 2024 23:364,91570,095,35822,858,00021,864,00093,102,080
19May 9, 2024 23:365,66084,499,82524,237,00027,267,00093,089,792
20May 9, 2024 23:496,71492,944,27526,042,00035,057,00093,294,592
21May 9, 2024 23:367,45999,667,36224,956,00042,924,00093,282,304
22May 9, 2024 23:497,572102,213,76524,965,00043,938,00093,184,000
23May 9, 2024 23:497,61593,764,15226,112,00043,186,00093,208,576
24May 9, 2024 23:367,62593,938,96526,145,00043,240,00093,134,848