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 11:50Joad NacerJoad NacerScore: 3,625Success
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 11:513,40762,257,95421,003,00010,001,00092,925,952
2May 22, 2024 11:513,42254,204,21920,090,00011,049,00092,979,200
3May 22, 2024 11:513,43358,485,88520,156,00011,086,00092,893,184
4May 22, 2024 11:513,43558,230,83120,165,00011,091,00093,138,944
5May 22, 2024 11:513,45955,541,97421,322,00010,153,00092,917,760
6May 22, 2024 11:513,46163,689,52520,321,00011,177,00093,208,576
7May 22, 2024 11:503,46462,488,24222,368,0009,150,00092,884,992
8May 22, 2024 11:503,48057,058,99620,781,00010,885,00092,852,224
9May 22, 2024 11:513,48058,389,07319,791,00011,874,00092,889,088
10May 22, 2024 11:513,48657,960,23620,817,00010,904,00092,938,240
11May 22, 2024 11:503,48856,910,10819,839,00011,903,00092,913,664
12May 22, 2024 11:513,49161,731,20119,854,00011,912,00092,901,376
13May 22, 2024 11:513,49263,259,82119,860,00011,916,00092,917,760
14May 22, 2024 11:513,49256,946,18219,863,00011,918,00092,921,856
15May 22, 2024 11:513,49559,175,36820,869,00010,931,00092,905,472
16May 22, 2024 11:513,49756,623,04919,892,00011,935,00092,942,336
17May 22, 2024 11:513,50158,069,61719,914,00011,948,00092,868,608
18May 22, 2024 11:513,50457,275,45420,926,00010,961,00092,925,952
19May 22, 2024 11:513,50559,480,97919,932,00011,959,00092,930,048
20May 22, 2024 11:513,50860,629,88219,952,00011,971,00092,889,088
21May 22, 2024 11:513,51057,681,45119,962,00011,977,00092,860,416
22May 22, 2024 11:513,51260,614,94020,972,00010,985,00092,901,376
23May 22, 2024 11:513,51356,049,54419,978,00011,987,00093,151,232
24May 22, 2024 11:513,51457,885,96619,984,00011,990,00092,930,048
25May 22, 2024 11:513,51660,477,44019,997,00011,998,00092,954,624
26May 22, 2024 11:513,52258,614,21220,029,00012,017,00092,876,800
27May 22, 2024 11:513,52559,718,26920,047,00012,028,00093,122,560
28May 22, 2024 11:513,52556,283,04620,051,00012,031,00092,925,952
29May 22, 2024 11:513,59766,355,05519,840,00012,896,00093,175,808
30May 22, 2024 11:513,61297,213,06432,866,329094,486,528
31May 22, 2024 11:513,614105,386,76732,889,387094,482,432
32May 22, 2024 11:503,617105,329,57132,914,513094,748,672
33May 22, 2024 11:513,618102,105,61732,920,488094,490,624
34May 22, 2024 11:503,62099,526,05732,942,868094,478,336
35May 22, 2024 11:513,621106,111,43032,949,460094,498,816
36May 22, 2024 11:513,623116,099,87332,969,738094,756,864
37May 22, 2024 11:513,625106,330,47732,991,390094,490,624
38May 22, 2024 11:513,633103,561,01333,060,819094,486,528
39May 22, 2024 11:513,634104,931,09733,073,152094,486,528
40May 22, 2024 11:503,63598,696,87533,075,168094,494,720
41May 22, 2024 11:513,63799,545,59633,098,752094,478,336
42May 22, 2024 11:513,643101,743,66633,152,487094,625,792
43May 22, 2024 11:513,64894,371,28733,194,282094,482,432
44May 22, 2024 11:513,65091,987,01933,218,752094,486,528
45May 22, 2024 11:513,658107,138,39633,289,358094,613,504
46May 22, 2024 11:513,66292,588,61733,319,653094,498,816
47May 22, 2024 11:513,748110,289,70434,108,622094,621,696
48May 22, 2024 11:514,03969,037,89720,859,00015,893,00093,126,656
49May 22, 2024 11:504,13863,748,82820,809,00016,845,00093,110,272
50May 22, 2024 11:514,20562,900,41821,145,00017,118,00093,106,176
51May 22, 2024 11:504,20861,693,94121,161,00017,130,00093,110,272
52May 22, 2024 11:514,51968,572,09922,064,00019,056,00093,081,600
53May 22, 2024 11:514,60368,382,42521,943,00019,948,00093,118,464
54May 22, 2024 11:515,84477,568,09223,080,00030,104,00093,007,872
55May 22, 2024 11:516,23680,933,19822,898,00033,849,00093,196,288
56May 22, 2024 11:516,27582,193,13423,041,00034,060,00093,265,920
57May 22, 2024 11:516,45986,281,92824,904,00033,870,00093,179,904
58May 22, 2024 11:506,65791,323,64323,223,00037,359,00093,159,424
59May 22, 2024 11:517,07187,294,29824,130,00040,218,00093,245,440
60May 22, 2024 11:517,10093,204,03725,239,00039,373,00093,188,096
61May 22, 2024 11:517,16092,264,21524,058,00041,099,00093,138,944
62May 22, 2024 11:517,35693,354,83723,979,00042,963,00093,319,168
63May 22, 2024 11:517,425102,121,21424,202,00043,362,00093,159,424
64May 22, 2024 11:517,42798,268,25024,209,00043,375,00093,192,192
65May 22, 2024 11:507,456101,343,79023,946,00043,901,00093,335,552
66May 22, 2024 11:517,48991,518,19524,051,00044,095,00093,282,304
67May 22, 2024 11:517,50191,511,04125,096,00043,165,00093,351,936
68May 22, 2024 11:517,51298,853,96625,133,00043,229,00093,167,616
69May 22, 2024 11:507,51694,030,02925,147,00043,253,00093,171,712
70May 22, 2024 11:517,52593,720,09525,177,00043,305,00093,216,768
71May 22, 2024 11:517,55998,866,52024,921,00043,862,00093,216,768
72May 22, 2024 11:507,562101,410,18823,936,00044,881,00093,306,880