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 27, 2024 14:43Joad NacerJoad NacerScore: 3,401Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 14:433,26653,839,17219,817,0009,908,00093,085,696
2Jul 27, 2024 14:433,27254,651,83819,851,0009,925,00092,905,472
3Jul 27, 2024 14:433,27460,083,92919,863,0009,931,00093,073,408
4Jul 27, 2024 14:433,27755,226,44519,883,0009,941,00093,179,904
5Jul 27, 2024 14:433,28361,392,07519,919,0009,959,00092,942,336
6Jul 27, 2024 14:433,28756,983,15918,944,00010,967,00093,048,832
7Jul 27, 2024 14:433,40167,504,88430,949,794094,494,720
8Jul 27, 2024 14:433,40385,859,46930,968,516094,498,816
9Jul 27, 2024 14:433,414117,555,73331,063,131094,629,888
10Jul 27, 2024 14:434,08362,998,75220,082,00017,069,00093,147,136
11Jul 27, 2024 14:435,29467,790,30621,075,00027,096,00093,188,096
12Jul 27, 2024 14:435,44275,047,16422,236,00027,290,00093,167,616