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 00:33Joad 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 00:333,42159,456,11921,088,00010,042,00092,917,760
2May 22, 2024 00:333,42453,138,80520,103,00011,057,00092,905,472
3May 22, 2024 00:333,43454,295,96720,162,00011,089,00092,962,816
4May 22, 2024 00:333,44560,324,29921,235,00010,111,00092,917,760
5May 22, 2024 00:333,50560,293,67819,938,00011,962,00092,889,088
6May 22, 2024 00:333,50560,775,39019,935,00011,961,00092,893,184
7May 22, 2024 00:333,51062,361,37419,962,00011,977,00093,143,040
8May 22, 2024 00:333,51463,225,21120,986,00010,993,00092,839,936
9May 22, 2024 00:333,62759,654,80720,006,00013,004,00093,155,328
10May 22, 2024 00:333,64399,581,51133,155,319094,494,720
11May 22, 2024 00:333,644100,184,73933,160,075094,482,432
12May 22, 2024 00:333,65099,766,70833,213,385094,494,720
13May 22, 2024 00:333,66092,796,60933,301,640094,486,528
14May 22, 2024 00:333,661108,552,66033,316,159094,494,720
15May 22, 2024 00:333,66597,297,23333,349,723094,490,624
16May 22, 2024 00:334,82370,181,79821,946,00021,946,00093,102,080
17May 22, 2024 00:335,05069,160,54321,978,00023,976,00093,003,776
18May 22, 2024 00:335,19474,044,34624,135,00023,130,00093,073,408
19May 22, 2024 00:337,20195,145,90824,194,00041,333,00093,274,112
20May 22, 2024 00:337,462102,781,80024,964,00042,938,00093,270,016
21May 22, 2024 00:337,47689,773,36524,011,00044,021,00093,327,360
22May 22, 2024 00:337,505104,093,63625,110,00043,190,00093,249,536
23May 22, 2024 00:337,51292,871,36125,133,00043,228,00093,257,728
24May 22, 2024 00:337,56497,936,18625,937,00042,896,00093,233,152