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:54Joad NacerJoad NacerScore: 4,064Success
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:493,99868,190,38226,273,00010,105,00092,917,760
2Apr 21, 2024 23:494,00863,026,55827,353,0009,117,00092,942,336
3Apr 21, 2024 23:514,01169,027,36627,374,0009,124,00092,925,952
4Apr 21, 2024 23:544,01658,772,43926,392,00010,150,00092,897,280
5Apr 21, 2024 23:514,02871,281,52525,755,00010,896,00093,192,192
6Apr 21, 2024 23:544,03067,050,84224,781,00011,895,00092,901,376
7Apr 21, 2024 23:514,03462,936,38025,797,00010,914,00092,966,912
8Apr 21, 2024 23:544,03765,798,97624,823,00011,915,00092,893,184
9Apr 21, 2024 23:494,03867,180,00225,820,00010,923,00092,962,816
10Apr 21, 2024 23:514,04162,746,00425,842,00010,933,00092,954,624
11Apr 21, 2024 23:494,04364,108,30324,858,00011,931,00092,938,240
12Apr 21, 2024 23:494,04362,441,72224,857,00011,931,00092,889,088
13Apr 21, 2024 23:544,04860,497,74824,890,00011,947,00092,794,880
14Apr 21, 2024 23:514,05463,201,53124,924,00011,963,00092,889,088
15Apr 21, 2024 23:544,06064,354,13025,964,00010,984,00092,860,416
16Apr 21, 2024 23:514,06262,634,24424,977,00011,989,00092,946,432
17Apr 21, 2024 23:514,06267,030,35925,972,00010,988,00092,901,376
18Apr 21, 2024 23:544,06263,095,24925,973,00010,988,00092,905,472
19Apr 21, 2024 23:514,06469,061,80724,986,00011,993,00092,921,856
20Apr 21, 2024 23:544,06562,150,14825,992,00010,996,00092,950,528
21Apr 21, 2024 23:494,07662,798,08925,063,00012,030,00092,917,760
22Apr 21, 2024 23:494,08165,149,30825,092,00012,044,00092,913,664
23Apr 21, 2024 23:514,26897,427,18138,834,809094,498,816
24Apr 21, 2024 23:544,283106,471,35938,971,005094,490,624
25Apr 21, 2024 23:494,289104,416,39239,034,134094,490,624
26Apr 21, 2024 23:544,293109,839,40339,063,335094,478,336
27Apr 21, 2024 23:514,29496,033,50339,072,926094,486,528
28Apr 21, 2024 23:514,29597,102,42439,087,961094,605,312
29Apr 21, 2024 23:494,297107,709,12839,100,703094,490,624
30Apr 21, 2024 23:544,302103,233,58139,145,878094,605,312
31Apr 21, 2024 23:494,304106,298,04339,163,352094,490,624
32Apr 21, 2024 23:494,31560,753,45825,174,00014,097,00092,921,856
33Apr 21, 2024 23:494,35272,632,70427,417,00012,185,00092,950,528
34Apr 21, 2024 23:514,61067,196,64425,970,00015,981,00093,163,520
35Apr 21, 2024 23:545,03481,025,33526,889,00018,921,00093,196,288
36Apr 21, 2024 23:545,10273,042,88327,251,00019,176,00093,208,576