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 listApr 21, 2024 23:20Joad NacerJoad NacerScore: 4,621Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:204,33864,765,68429,354,00010,122,00092,864,512
2Apr 21, 2024 23:184,35267,430,26229,446,00010,154,00092,905,472
3Apr 21, 2024 23:204,36364,373,50128,783,00010,917,00092,917,760
4Apr 21, 2024 23:184,36666,032,04128,808,00010,927,00092,913,664
5Apr 21, 2024 23:204,36667,957,04229,798,0009,932,00092,872,704
6Apr 21, 2024 23:204,37265,995,03528,845,00010,941,00092,938,240
7Apr 21, 2024 23:184,37465,453,21228,860,00010,947,00092,987,392
8Apr 21, 2024 23:184,37569,625,29428,863,00010,948,00092,872,704
9Apr 21, 2024 23:204,38869,312,49927,953,00011,979,00093,163,520
10Apr 21, 2024 23:184,39464,486,98628,989,00010,995,00092,909,568
11Apr 21, 2024 23:204,39568,591,41527,994,00011,997,00092,880,896
12Apr 21, 2024 23:184,39765,894,29228,011,00012,004,00092,925,952
13Apr 21, 2024 23:204,39866,161,39128,018,00012,007,00092,954,624
14Apr 21, 2024 23:204,40866,336,31228,078,00012,033,00092,942,336
15Apr 21, 2024 23:204,41665,515,40929,137,00011,051,00092,950,528
16Apr 21, 2024 23:204,42165,837,22928,159,00012,068,00092,880,896
17Apr 21, 2024 23:204,43269,874,06628,234,00012,100,00092,876,800
18Apr 21, 2024 23:204,44773,631,07129,341,00011,129,00093,179,904
19Apr 21, 2024 23:184,621108,427,05542,051,051094,490,624
20Apr 21, 2024 23:204,629102,712,19042,123,387094,482,432
21Apr 21, 2024 23:184,632104,641,38242,148,810094,498,816
22Apr 21, 2024 23:204,63398,723,29742,156,688094,486,528
23Apr 21, 2024 23:204,634102,342,26542,171,391094,756,864
24Apr 21, 2024 23:204,642100,930,02342,239,550094,486,528
25Apr 21, 2024 23:184,651114,306,28042,324,136094,605,312
26Apr 21, 2024 23:204,655114,552,46442,364,710094,490,624
27Apr 21, 2024 23:204,661119,827,56042,418,695094,482,432
28Apr 21, 2024 23:204,75665,854,01728,180,00015,096,00092,925,952
29Apr 21, 2024 23:204,88770,655,16730,323,00014,150,00092,921,856
30Apr 21, 2024 23:185,00570,001,44129,354,00016,195,00093,138,944
31Apr 21, 2024 23:185,28378,732,55430,046,00018,027,00093,192,192
32Apr 21, 2024 23:206,34782,841,45329,877,00027,885,00093,106,176
33Apr 21, 2024 23:186,36985,550,84829,980,00027,981,00093,138,944
34Apr 21, 2024 23:206,48290,004,91229,994,00028,994,00093,089,792
35Apr 21, 2024 23:206,56085,531,96831,364,00028,329,00093,151,232
36Apr 21, 2024 23:206,82089,688,72532,033,00030,031,00093,097,984