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 22, 2024 01:07Joad NacerJoad NacerScore: 3,670Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 01:073,42859,255,62220,127,00011,070,00092,921,856
2May 22, 2024 01:073,44754,587,01122,260,0009,106,00092,946,432
3May 22, 2024 01:073,46053,888,12521,332,00010,158,00092,917,760
4May 22, 2024 01:073,46560,449,02422,380,0009,155,00092,966,912
5May 22, 2024 01:073,48760,830,52319,831,00011,899,00092,917,760
6May 22, 2024 01:073,51060,564,10220,963,00010,980,00092,966,912
7May 22, 2024 01:073,54355,892,63220,152,00012,091,00093,151,232
8May 22, 2024 01:073,639104,958,04733,110,443094,482,432
9May 22, 2024 01:073,640101,629,09333,119,521094,613,504
10May 22, 2024 01:073,65481,920,43333,250,932094,494,720
11May 22, 2024 01:073,65895,851,97033,284,139094,482,432
12May 22, 2024 01:073,66194,743,86333,313,968094,752,768
13May 22, 2024 01:073,67054,105,13622,262,00011,131,00093,192,192
14May 22, 2024 01:073,68992,858,03933,571,021094,490,624
15May 22, 2024 01:073,84863,676,62421,011,00014,007,00093,159,424
16May 22, 2024 01:073,89661,636,96421,270,00014,180,00093,118,464
17May 22, 2024 01:074,24665,503,31422,787,00015,852,00092,966,912
18May 22, 2024 01:074,26068,888,75522,863,00015,905,00093,126,656
19May 22, 2024 01:077,08687,908,60325,187,00039,292,00093,278,208
20May 22, 2024 01:077,37791,947,14826,052,00041,082,00093,261,824
21May 22, 2024 01:077,453100,099,56324,935,00042,889,00093,253,632
22May 22, 2024 01:077,47793,138,71326,015,00042,025,00093,175,808
23May 22, 2024 01:077,58597,380,37625,010,00044,018,00093,290,496
24May 22, 2024 01:077,60192,470,19726,065,00043,108,00093,261,824