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:37Joad NacerJoad NacerScore: 4,044Success
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:533,94266,745,91026,651,0009,225,00092,954,624
2Apr 22, 2024 00:073,94763,503,01124,941,00010,974,00092,983,296
3Apr 21, 2024 23:313,95362,724,82625,983,0009,993,00092,971,008
4Apr 21, 2024 23:313,95462,526,24225,985,0009,994,00092,893,184
5Apr 22, 2024 00:073,96063,970,93625,028,00011,012,00092,966,912
6Apr 21, 2024 23:533,96162,067,33226,033,00010,012,00092,946,432
7Apr 21, 2024 23:373,96560,668,18525,057,00011,025,00092,889,088
8Apr 21, 2024 23:533,96763,172,57625,072,00011,032,00092,860,416
9Apr 21, 2024 23:533,96759,951,09925,067,00011,029,00093,007,872
10Apr 21, 2024 23:373,98863,030,84925,202,00011,089,00092,852,224
11Apr 21, 2024 23:533,99362,775,61825,234,00011,103,00092,897,280
12Apr 22, 2024 00:073,99660,395,57725,254,00011,111,00092,901,376
13Apr 21, 2024 23:313,99862,248,31425,267,00011,117,00092,905,472
14Apr 21, 2024 23:373,99858,876,88625,265,00011,116,00092,884,992
15Apr 21, 2024 23:374,00561,515,65525,308,00011,135,00092,889,088
16Apr 21, 2024 23:534,00763,034,53025,324,00011,142,00092,880,896
17Apr 22, 2024 00:074,00765,128,85825,324,00011,142,00092,880,896
18Apr 21, 2024 23:314,01263,124,85225,352,00011,154,00092,872,704
19Apr 22, 2024 00:074,01965,034,70025,401,00011,176,00092,954,624
20Apr 21, 2024 23:314,02163,823,32625,408,00011,179,00092,901,376
21Apr 21, 2024 23:534,02369,197,23225,425,00011,187,00092,925,952
22Apr 21, 2024 23:374,02562,411,27324,750,00011,880,00092,901,376
23Apr 21, 2024 23:534,03464,266,34924,803,00011,905,00092,925,952
24Apr 22, 2024 00:074,03569,512,51725,803,00010,916,00092,917,760
25Apr 21, 2024 23:374,04462,563,74824,863,00011,934,00092,930,048
26Apr 21, 2024 23:314,04764,938,68024,886,00011,945,00092,897,280
27Apr 21, 2024 23:314,14992,811,89537,755,836094,486,528
28Apr 21, 2024 23:374,156110,329,65337,820,432094,502,912
29Apr 21, 2024 23:534,15893,325,15437,833,397094,617,600
30Apr 22, 2024 00:074,159100,683,38637,850,322094,494,720
31Apr 21, 2024 23:374,16397,030,82037,886,648094,486,528
32Apr 21, 2024 23:314,165109,473,16937,900,367094,482,432
33Apr 22, 2024 00:074,165104,529,15637,904,036094,486,528
34Apr 21, 2024 23:534,167114,315,54337,918,557094,621,696
35Apr 21, 2024 23:374,167101,061,06837,917,100094,490,624
36Apr 21, 2024 23:314,171105,825,99237,952,999094,560,256
37Apr 21, 2024 23:534,179107,236,22438,027,820094,482,432
38Apr 22, 2024 00:074,186106,304,85138,095,125094,486,528
39Apr 22, 2024 00:074,38268,215,85625,922,00013,958,00093,077,504
40Apr 21, 2024 23:314,44165,150,22726,269,00014,145,00092,897,280
41Apr 21, 2024 23:374,45168,593,49326,330,00014,178,00092,930,048
42Apr 21, 2024 23:374,48272,761,76626,861,00013,928,00092,884,992
43Apr 21, 2024 23:314,57269,884,31826,385,00015,222,00092,942,336
44Apr 21, 2024 23:374,64366,953,03725,152,00017,103,00093,048,832
45Apr 22, 2024 00:074,71166,433,25826,921,00015,953,00093,171,712
46Apr 21, 2024 23:315,20377,489,54427,202,00020,149,00093,184,000
47Apr 21, 2024 23:535,44779,349,43128,750,00020,819,00093,204,480
48Apr 22, 2024 00:075,56477,508,41528,356,00022,279,00093,167,616