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:51Joad NacerJoad NacerScore: 3,773Success
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:513,54554,826,89222,181,00010,082,00092,930,048
2May 9, 2024 23:523,55560,485,86222,241,00010,109,00093,184,000
3May 9, 2024 23:523,58662,369,75922,435,00010,198,00092,889,088
4May 9, 2024 23:523,59656,686,99520,825,00011,900,00093,081,600
5May 9, 2024 23:523,60363,467,28620,862,00011,921,00093,200,384
6May 9, 2024 23:513,60764,798,04320,887,00011,935,00092,925,952
7May 9, 2024 23:523,62261,493,02120,974,00011,985,00092,942,336
8May 9, 2024 23:513,62661,732,07421,996,00010,998,00093,175,808
9May 9, 2024 23:513,63357,641,10421,040,00012,022,00092,893,184
10May 9, 2024 23:523,63361,156,30421,041,00012,023,00092,831,744
11May 9, 2024 23:513,766107,499,63134,270,893094,478,336
12May 9, 2024 23:523,766109,484,96534,270,150094,482,432
13May 9, 2024 23:523,773104,156,94734,333,610094,486,528
14May 9, 2024 23:513,774103,211,37334,343,973094,601,216
15May 9, 2024 23:523,77786,350,90534,374,420094,609,408
16May 9, 2024 23:513,78999,524,96934,479,321094,609,408
17May 9, 2024 23:514,05062,516,24422,910,00013,945,00093,167,616
18May 9, 2024 23:514,37566,676,47222,890,00016,919,00093,118,464
19May 9, 2024 23:526,35785,173,70623,937,00033,910,00093,077,504
20May 9, 2024 23:526,46579,824,04125,925,00032,906,00093,106,176
21May 9, 2024 23:517,49296,842,67326,069,00042,111,00093,241,344
22May 9, 2024 23:517,52890,675,45426,194,00042,313,00093,286,400
23May 9, 2024 23:517,530102,113,73226,199,00042,322,00093,167,616
24May 9, 2024 23:527,55894,936,75025,918,00042,864,00093,220,864