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 listJul 28, 2024 12:25Yuriy LyfenkoYuriy LyfenkoScore: 3,469Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 28, 2024 12:253,305652,676,29525,060,0005,012,00092,884,992
2Jul 28, 2024 12:253,310652,285,22122,088,0008,032,00093,208,576
3Jul 28, 2024 12:253,315661,178,04021,842,0008,320,00093,188,096
4Jul 28, 2024 12:253,320650,195,36623,164,0007,050,00093,212,672
5Jul 28, 2024 12:253,322647,846,97522,167,0008,061,00092,884,992
6Jul 28, 2024 12:253,324655,925,44522,945,0007,300,00093,204,480
7Jul 28, 2024 12:253,329649,058,29824,237,0006,059,00093,081,600
8Jul 28, 2024 12:253,336650,149,56724,289,0006,072,00093,073,408
9Jul 28, 2024 12:253,338649,744,41724,299,0006,074,00093,077,504
10Jul 28, 2024 12:253,340653,786,27622,287,0008,104,00093,138,944
11Jul 28, 2024 12:253,463691,130,06831,517,136094,707,712
12Jul 28, 2024 12:253,468686,886,82431,560,902094,646,272
13Jul 28, 2024 12:253,469693,612,22631,563,732094,609,408
14Jul 28, 2024 12:253,475699,974,61831,624,816094,777,344
15Jul 28, 2024 12:253,478691,634,82531,650,711094,650,368
16Jul 28, 2024 12:253,481682,766,35331,677,475094,613,504
17Jul 28, 2024 12:254,382660,700,87426,583,00013,291,00093,192,192
18Jul 28, 2024 12:254,428663,097,74425,185,00015,111,00093,184,000
19Jul 28, 2024 12:254,745666,087,10227,115,00016,068,00093,171,712
20Jul 28, 2024 12:256,059680,390,92431,075,00024,058,00093,110,272
21Jul 28, 2024 12:256,727689,886,27629,103,00032,114,00093,339,648
22Jul 28, 2024 12:256,827684,804,05725,049,00037,073,00093,073,408
23Jul 28, 2024 12:256,897691,059,01028,892,00033,874,00093,331,456
24Jul 28, 2024 12:257,072686,699,86829,624,00034,731,00093,237,248