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 9, 2024 23:18Joad NacerJoad NacerScore: 4,131Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:183,78161,231,40824,288,00010,120,00092,925,952
2May 9, 2024 23:183,78256,972,26122,269,00012,147,00092,823,552
3May 9, 2024 23:183,78457,405,60823,291,00011,139,00092,971,008
4May 9, 2024 23:183,78557,728,47824,315,00010,131,00092,950,528
5May 9, 2024 23:183,83062,604,99326,890,0007,967,00093,110,272
6May 9, 2024 23:184,12197,890,53337,501,455094,486,528
7May 9, 2024 23:184,131105,459,26237,594,410094,482,432
8May 9, 2024 23:184,13691,437,94137,638,077094,482,432
9May 9, 2024 23:185,31279,897,64623,163,00025,177,00093,118,464
10May 9, 2024 23:187,20297,409,49327,224,00038,315,00093,089,792
11May 9, 2024 23:187,25191,145,05129,992,00035,991,00093,085,696
12May 9, 2024 23:187,864101,241,45831,247,00040,319,00093,270,016