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:38Joad NacerJoad NacerScore: 3,766Success
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:383,53957,465,08621,134,00011,070,00092,913,664
2May 12, 2024 00:383,56354,360,72621,279,00011,146,00093,155,328
3May 12, 2024 00:383,56960,710,62422,326,00010,148,00092,897,280
4May 12, 2024 00:383,57659,627,31922,373,00010,169,00093,159,424
5May 12, 2024 00:383,63861,568,26421,067,00012,038,00092,905,472
6May 12, 2024 00:383,64560,085,10921,109,00012,062,00092,839,936
7May 12, 2024 00:383,76693,299,26034,269,429094,490,624
8May 12, 2024 00:383,796104,571,41434,540,448094,482,432
9May 12, 2024 00:383,79795,026,48234,555,713094,601,216
10May 12, 2024 00:385,99581,520,95425,259,00029,300,00093,016,064
11May 12, 2024 00:386,54287,267,70925,225,00034,306,00093,220,864
12May 12, 2024 00:387,09292,409,93025,208,00039,325,00093,077,504