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 18:40AnSaAnSaScore: 4,377Success
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 18:403,60262,065,63019,868,00012,914,00097,157,120
2Jun 24, 2024 18:403,62058,028,95721,964,00010,982,00097,161,216
3Jun 24, 2024 18:403,64261,102,37718,080,00015,066,00097,243,136
4Jun 24, 2024 18:404,35065,019,23918,802,00020,781,00097,431,552
5Jun 24, 2024 18:404,35797,791,88039,650,485098,803,712
6Jun 24, 2024 18:404,366106,524,07539,730,515098,930,688
7Jun 24, 2024 18:404,377107,415,49639,830,738099,069,952
8Jun 24, 2024 18:404,38371,290,40520,941,00018,947,00097,472,512
9Jun 24, 2024 18:405,69883,904,25321,938,00029,915,00097,411,072
10Jun 24, 2024 18:407,64899,589,35429,252,00040,347,00097,726,464
11Jun 24, 2024 18:408,751108,713,60431,248,00048,385,00097,738,752
12Jun 24, 2024 18:408,770111,710,87533,917,00045,888,00097,525,760