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 20, 2024 23:58Joad NacerJoad NacerScore: 3,794Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 20, 2024 23:583,43858,734,96520,183,00011,101,00092,909,568
2May 20, 2024 23:583,43852,616,53320,186,00011,102,00092,905,472
3May 20, 2024 23:583,44454,018,68621,229,00010,109,00092,930,048
4May 20, 2024 23:583,45354,272,76621,286,00010,136,00093,110,272
5May 20, 2024 23:583,46161,558,69120,319,00011,175,00092,889,088
6May 20, 2024 23:583,791109,179,61834,494,198094,482,432
7May 20, 2024 23:583,79499,924,03134,524,614094,486,528
8May 20, 2024 23:583,83288,723,52534,874,358094,605,312
9May 20, 2024 23:583,91361,576,37919,782,00015,825,00093,110,272
10May 20, 2024 23:586,05879,654,48726,060,00029,067,00092,995,584
11May 20, 2024 23:586,24184,255,46826,902,00029,891,00093,106,176
12May 20, 2024 23:587,49592,721,50630,090,00038,114,00093,265,920