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 01:47Joad NacerJoad NacerScore: 3,660Success
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 01:473,43256,562,43721,155,00010,073,00092,852,224
2May 22, 2024 01:463,44664,237,94722,258,0009,105,00092,913,664
3May 22, 2024 01:463,45255,200,83721,282,00010,134,00092,950,528
4May 22, 2024 01:473,45861,837,15621,317,00010,151,00093,106,176
5May 22, 2024 01:473,45855,054,35222,334,0009,136,00092,938,240
6May 22, 2024 01:463,49659,034,79320,523,00011,288,00092,893,184
7May 22, 2024 01:463,50257,406,44319,918,00011,951,00092,909,568
8May 22, 2024 01:473,50459,136,28319,927,00011,956,00092,880,896
9May 22, 2024 01:473,50768,381,89619,946,00011,968,00092,950,528
10May 22, 2024 01:473,51358,683,45220,978,00010,988,00092,889,088
11May 22, 2024 01:473,51456,996,05319,985,00011,991,00093,143,040
12May 22, 2024 01:473,52060,318,29921,020,00011,010,00092,962,816
13May 22, 2024 01:463,53265,834,18720,086,00012,051,00092,897,280
14May 22, 2024 01:463,635103,548,52233,082,931094,486,528
15May 22, 2024 01:473,63697,768,80933,088,937094,486,528
16May 22, 2024 01:463,64394,983,71433,154,306094,478,336
17May 22, 2024 01:473,64697,942,01033,178,772094,617,600
18May 22, 2024 01:473,65993,527,63933,292,838094,474,240
19May 22, 2024 01:473,66094,891,26133,307,301094,482,432
20May 22, 2024 01:473,660112,874,41333,307,991094,498,816
21May 22, 2024 01:473,667103,251,52033,366,947094,625,792
22May 22, 2024 01:463,67798,474,09133,464,876094,617,600
23May 22, 2024 01:473,70666,626,37920,831,00012,895,00093,134,848
24May 22, 2024 01:463,71059,644,35720,851,00012,907,00093,077,504
25May 22, 2024 01:473,83864,819,48121,955,00012,973,00093,106,176
26May 22, 2024 01:473,98167,028,24122,138,00014,088,00093,118,464
27May 22, 2024 01:475,16770,274,72023,009,00024,010,00093,089,792
28May 22, 2024 01:466,15283,711,48222,992,00032,989,00093,310,976
29May 22, 2024 01:477,24888,748,75323,985,00041,974,00093,323,264
30May 22, 2024 01:467,25194,476,24123,995,00041,992,00093,220,864
31May 22, 2024 01:467,38194,652,64724,059,00043,107,00093,114,368
32May 22, 2024 01:477,47593,594,82024,006,00044,012,00093,253,632
33May 22, 2024 01:477,48398,648,14625,035,00043,061,00093,192,192
34May 22, 2024 01:477,48395,846,20125,035,00043,060,00093,155,328
35May 22, 2024 01:477,50891,826,92325,119,00043,205,00093,286,400
36May 22, 2024 01:477,51093,438,47125,125,00043,215,00093,216,768