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 17:51Joad NacerJoad NacerScore: 3,617Success
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 17:513,41960,886,49920,071,00011,039,00092,905,472
2May 22, 2024 17:513,41959,566,34920,072,00011,039,00092,925,952
3May 22, 2024 17:513,42257,911,30520,089,00011,049,00092,958,720
4May 22, 2024 17:513,42955,678,86420,133,00011,073,00092,901,376
5May 22, 2024 17:513,45354,798,36620,273,00011,150,00092,901,376
6May 22, 2024 17:513,47763,171,50220,767,00010,878,00092,884,992
7May 22, 2024 17:513,47958,785,25219,787,00011,872,00092,917,760
8May 22, 2024 17:513,47960,760,27320,778,00010,883,00092,852,224
9May 22, 2024 17:513,48557,699,19019,819,00011,891,00092,971,008
10May 22, 2024 17:513,48663,069,96221,812,0009,914,00093,114,368
11May 22, 2024 17:513,48758,995,57320,826,00010,909,00092,880,896
12May 22, 2024 17:513,48759,684,38019,831,00011,898,00092,999,680
13May 22, 2024 17:513,48862,320,11819,838,00011,903,00092,934,144
14May 22, 2024 17:513,48958,173,44020,834,00010,913,00092,954,624
15May 22, 2024 17:513,49056,389,74321,833,0009,924,00092,909,568
16May 22, 2024 17:513,49656,341,89419,883,00011,929,00092,844,032
17May 22, 2024 17:513,49761,948,04819,891,00011,934,00092,889,088
18May 22, 2024 17:513,50060,292,54219,904,00011,942,00092,827,648
19May 22, 2024 17:513,50860,008,75420,948,00010,972,00092,909,568
20May 22, 2024 17:513,51059,311,94819,963,00011,978,00092,876,800
21May 22, 2024 17:513,51156,842,99620,965,00010,981,00092,958,720
22May 22, 2024 17:513,51259,137,05319,973,00011,983,00092,958,720
23May 22, 2024 17:513,51558,205,77220,994,00010,997,00092,848,128
24May 22, 2024 17:513,51664,029,06719,999,00011,999,00092,876,800
25May 22, 2024 17:513,594115,430,25732,704,755094,482,432
26May 22, 2024 17:513,59697,380,09032,720,034094,490,624
27May 22, 2024 17:513,596108,503,76432,724,535094,494,720
28May 22, 2024 17:513,60193,371,45432,772,613094,490,624
29May 22, 2024 17:513,60889,217,64032,828,520094,478,336
30May 22, 2024 17:513,61495,835,45132,885,098094,490,624
31May 22, 2024 17:513,617101,445,81632,916,611094,494,720
32May 22, 2024 17:513,61894,296,35032,928,138094,490,624
33May 22, 2024 17:513,62198,861,55232,947,904094,498,816
34May 22, 2024 17:513,621114,360,58932,948,082094,482,432
35May 22, 2024 17:513,626108,007,67732,995,785094,486,528
36May 22, 2024 17:513,629103,969,20933,020,505094,486,528
37May 22, 2024 17:513,63596,209,75233,079,202094,486,528
38May 22, 2024 17:513,638101,888,82533,106,667094,621,696
39May 22, 2024 17:513,64288,217,66533,138,496094,617,600
40May 22, 2024 17:513,65156,022,23821,142,00012,081,00092,946,432
41May 22, 2024 17:513,92265,465,75220,817,00014,869,00093,089,792
42May 22, 2024 17:514,13063,738,81520,315,00017,267,00093,155,328
43May 22, 2024 17:514,52466,160,97521,088,00020,084,00093,110,272
44May 22, 2024 17:514,73567,416,66922,046,00021,044,00093,069,312
45May 22, 2024 17:515,49973,493,78522,018,00028,023,00093,065,216
46May 22, 2024 17:515,49982,707,00822,017,00028,022,00093,069,312
47May 22, 2024 17:515,87878,862,98223,211,00030,275,00092,979,200
48May 22, 2024 17:515,92783,061,94321,975,00031,964,00093,216,768
49May 22, 2024 17:516,13091,546,53423,908,00031,878,00093,286,400
50May 22, 2024 17:516,30780,300,88823,158,00034,234,00093,327,360
51May 22, 2024 17:516,63184,837,80823,130,00037,210,00093,155,328
52May 22, 2024 17:516,73384,468,17724,106,00037,163,00093,294,592
53May 22, 2024 17:516,85991,553,56524,161,00038,255,00093,282,304
54May 22, 2024 17:517,01389,871,82023,932,00039,887,00093,155,328
55May 22, 2024 17:517,17994,595,54425,125,00040,200,00093,245,440
56May 22, 2024 17:517,19093,631,24624,157,00041,269,00093,130,752
57May 22, 2024 17:517,41891,472,76025,189,00042,317,00093,114,368
58May 22, 2024 17:517,47290,290,17523,999,00043,999,00093,200,384
59May 22, 2024 17:517,49295,552,95027,069,00041,105,00093,077,504
60May 22, 2024 17:517,57389,475,12723,971,00044,945,00093,151,232