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 21, 2024 23:28Joad NacerJoad NacerScore: 3,990Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 21, 2024 23:303,44257,752,06321,219,00010,104,00092,860,416
2May 21, 2024 23:303,44252,792,74721,216,00010,103,00092,897,280
3May 21, 2024 23:283,45154,360,00620,262,00011,144,00092,975,104
4May 21, 2024 23:293,48558,016,53219,823,00011,894,00092,860,416
5May 21, 2024 23:283,48959,903,91019,843,00011,905,00092,909,568
6May 21, 2024 23:303,50263,182,67919,920,00011,952,00092,946,432
7May 21, 2024 23:283,50262,646,35420,914,00010,954,00092,917,760
8May 21, 2024 23:303,50762,317,15220,946,00010,972,00092,893,184
9May 21, 2024 23:283,51259,243,46319,974,00011,984,00093,224,960
10May 21, 2024 23:283,51559,061,69520,994,00010,997,00092,880,896
11May 21, 2024 23:283,51663,673,75319,995,00011,997,00092,872,704
12May 21, 2024 23:303,51860,004,16520,006,00012,004,00092,852,224
13May 21, 2024 23:303,52158,959,96321,028,00011,014,00092,934,144
14May 21, 2024 23:283,52257,816,08220,032,00012,019,00092,893,184
15May 21, 2024 23:293,53058,386,64220,078,00012,047,00092,930,048
16May 21, 2024 23:293,54258,776,97220,144,00012,086,00092,934,144
17May 21, 2024 23:283,633113,963,18433,064,466094,474,240
18May 21, 2024 23:283,647103,018,73033,190,356094,490,624
19May 21, 2024 23:293,648107,664,92033,198,750094,478,336
20May 21, 2024 23:283,65896,286,06033,284,741094,486,528
21May 21, 2024 23:283,658106,334,74533,292,056094,482,432
22May 21, 2024 23:303,65894,473,91533,287,447094,490,624
23May 21, 2024 23:303,661106,215,82233,315,384094,625,792
24May 21, 2024 23:283,66298,540,77833,328,694094,490,624
25May 21, 2024 23:293,66487,376,29333,342,916094,490,624
26May 21, 2024 23:303,66583,686,33833,347,414094,617,600
27May 21, 2024 23:293,668109,533,88733,380,028094,494,720
28May 21, 2024 23:303,66999,848,63433,383,467094,490,624
29May 21, 2024 23:283,67192,351,97833,402,892094,617,600
30May 21, 2024 23:283,67290,483,89733,411,430094,621,696
31May 21, 2024 23:303,672113,130,17733,415,392094,621,696
32May 21, 2024 23:283,680117,129,44133,489,273094,605,312
33May 21, 2024 23:303,69093,952,39033,575,557094,482,432
34May 21, 2024 23:283,85098,359,98735,036,845094,613,504
35May 21, 2024 23:303,87854,811,64020,164,00015,123,00093,224,960
36May 21, 2024 23:283,98767,850,00321,167,00015,119,00093,118,464
37May 21, 2024 23:283,99063,527,82121,182,00015,130,00093,184,000
38May 21, 2024 23:283,99060,621,82922,190,00014,121,00093,110,272
39May 21, 2024 23:304,10464,403,89221,197,00016,150,00093,155,328
40May 21, 2024 23:294,15661,646,98120,902,00016,921,00093,085,696
41May 21, 2024 23:294,16063,518,87421,487,00016,371,00093,155,328
42May 21, 2024 23:304,54470,150,17721,179,00020,170,00093,077,504
43May 21, 2024 23:284,70572,554,22520,909,00021,904,00093,167,616
44May 21, 2024 23:284,78772,922,43822,289,00021,276,00093,118,464
45May 21, 2024 23:295,54974,718,06123,230,00027,270,00093,126,656
46May 21, 2024 23:305,92582,488,02323,963,00029,954,00093,220,864
47May 21, 2024 23:305,94680,962,33823,046,00031,062,00093,048,832
48May 21, 2024 23:306,15180,963,42722,991,00032,987,00093,302,784
49May 21, 2024 23:306,17480,688,65923,077,00033,110,00093,093,888
50May 21, 2024 23:286,39381,910,38223,068,00035,104,00093,302,784
51May 21, 2024 23:286,69386,972,80422,965,00037,943,00093,155,328
52May 21, 2024 23:286,75591,273,53026,200,00035,270,00093,163,520
53May 21, 2024 23:287,05089,020,89525,062,00039,097,00093,241,344
54May 21, 2024 23:287,09193,310,84824,199,00040,331,00093,294,592
55May 21, 2024 23:307,11990,454,23426,909,00037,873,00093,233,152
56May 21, 2024 23:287,18292,689,97825,137,00040,219,00093,286,400
57May 21, 2024 23:287,42598,853,16625,211,00042,355,00093,200,384
58May 21, 2024 23:287,47398,631,05724,002,00044,004,00093,245,440
59May 21, 2024 23:287,50291,266,63525,099,00043,170,00093,200,384
60May 21, 2024 23:287,50492,380,20725,105,00043,181,00093,335,552
61May 21, 2024 23:307,50898,427,35926,123,00042,199,00093,290,496
62May 21, 2024 23:297,52391,648,13125,170,00043,293,00093,261,824
63May 21, 2024 23:307,53096,948,02125,191,00043,329,00093,298,688
64May 21, 2024 23:307,538101,902,14725,218,00043,376,00093,122,560
65May 21, 2024 23:297,55898,811,99524,919,00043,859,00093,282,304
66May 21, 2024 23:287,560100,402,02524,925,00043,869,00093,282,304
67May 21, 2024 23:287,572100,009,83324,966,00043,941,00093,184,000
68May 21, 2024 23:287,58096,954,79024,991,00043,984,00093,274,112
69May 21, 2024 23:287,59196,616,52726,030,00043,050,00093,212,672
70May 21, 2024 23:297,59594,048,17725,040,00044,071,00093,315,072
71May 21, 2024 23:287,60595,913,78224,072,00045,136,00093,310,976
72May 21, 2024 23:307,64899,577,37825,217,00044,382,00093,323,264