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 12, 2024 00:36Joad NacerJoad NacerScore: 3,771Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 12, 2024 00:363,60857,046,16121,888,00010,944,00092,925,952
2May 12, 2024 00:363,61263,118,91720,914,00011,951,00092,925,952
3May 12, 2024 00:363,61862,866,27121,952,00010,976,00092,930,048
4May 12, 2024 00:363,62563,752,36520,993,00011,996,00092,925,952
5May 12, 2024 00:363,75399,448,71534,148,246094,490,624
6May 12, 2024 00:363,75386,228,77534,154,385094,494,720
7May 12, 2024 00:363,75797,326,42534,192,621094,486,528
8May 12, 2024 00:363,77199,674,81134,312,923094,490,624
9May 12, 2024 00:363,78196,254,77934,411,235094,482,432
10May 12, 2024 00:363,794104,515,17434,529,261094,486,528
11May 12, 2024 00:364,09465,416,12223,157,00014,095,00093,134,848
12May 12, 2024 00:364,49266,823,04522,932,00017,946,00093,040,640
13May 12, 2024 00:366,90492,998,99124,930,00037,895,00093,147,136
14May 12, 2024 00:367,49895,882,92726,089,00042,145,00093,347,840
15May 12, 2024 00:367,61392,670,36226,103,00043,171,00093,245,440