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 listJun 24, 2024 17:00AnSaAnSaScore: 4,370Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 24, 2024 17:003,50756,861,62919,946,00011,967,00092,606,464
2Jun 24, 2024 17:003,52657,642,06217,048,00015,043,00092,635,136
3Jun 24, 2024 17:003,52764,391,00918,054,00014,042,00092,643,328
4Jun 24, 2024 17:003,56361,880,02619,251,00013,172,00092,618,752
5Jun 24, 2024 17:004,17669,971,29217,000,00021,000,00092,848,128
6Jun 24, 2024 17:004,342105,102,30239,509,773094,748,672
7Jun 24, 2024 17:004,370107,701,31939,769,377094,613,504
8Jun 24, 2024 17:004,383125,910,72739,888,398094,621,696
9Jun 24, 2024 17:005,07372,993,83421,074,00025,088,00092,819,456
10Jun 24, 2024 17:006,84490,171,45118,080,00044,196,00093,020,160
11Jun 24, 2024 17:008,107102,419,89426,919,00046,859,00092,946,432
12Jun 24, 2024 17:008,554103,368,36221,954,00055,883,00093,007,872