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 9, 2024 23:32Joad NacerJoad NacerScore: 3,916Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:343,70360,428,24524,780,0008,920,00093,163,520
2May 9, 2024 23:323,70463,756,06922,800,00010,904,00092,889,088
3May 9, 2024 23:343,71365,234,70122,523,00011,261,00092,954,624
4May 9, 2024 23:343,71965,821,51021,897,00011,944,00092,942,336
5May 9, 2024 23:323,72260,346,00321,917,00011,955,00092,954,624
6May 9, 2024 23:343,74968,166,15623,076,00011,036,00092,942,336
7May 9, 2024 23:323,75164,247,24122,084,00012,046,00092,954,624
8May 9, 2024 23:343,75259,428,90523,099,00011,047,00092,938,240
9May 9, 2024 23:323,886107,941,91635,358,852094,486,528
10May 9, 2024 23:323,889107,550,32935,389,165094,605,312
11May 9, 2024 23:343,897107,486,03335,461,150094,605,312
12May 9, 2024 23:343,899103,800,22135,480,506094,482,432
13May 9, 2024 23:343,91699,047,94135,637,616094,609,408
14May 9, 2024 23:323,921100,936,95035,679,170094,486,528
15May 9, 2024 23:344,04468,676,35923,870,00012,930,00093,204,480
16May 9, 2024 23:324,06864,008,14522,013,00015,009,00093,159,424
17May 9, 2024 23:325,15881,767,23823,967,00022,968,00093,093,888
18May 9, 2024 23:325,97380,663,76325,165,00029,192,00093,212,672
19May 9, 2024 23:346,92685,897,78726,012,00037,017,00093,274,112
20May 9, 2024 23:347,36392,363,17628,001,00039,002,00093,274,112
21May 9, 2024 23:327,56498,687,13425,935,00042,893,00093,224,960
22May 9, 2024 23:327,602108,118,38726,067,00043,112,00093,347,840
23May 9, 2024 23:347,62192,609,66227,136,00042,212,00093,204,480
24May 9, 2024 23:327,77896,193,13125,920,00044,861,00093,200,384