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 26, 2021 18:18Sergey StreminSergey StreminScore: 5,101Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 26, 2021 18:184,91470,710,02231,801,00012,919,00094,564,352
2May 26, 2021 18:184,944105,206,61944,994,391094,674,944
3May 26, 2021 18:184,992104,991,02045,424,108094,679,040
4May 26, 2021 18:185,04072,052,31334,894,00010,966,00094,711,808
5May 26, 2021 18:185,06571,077,50440,078,0006,011,00094,560,256
6May 26, 2021 18:185,06969,285,69032,087,00014,038,00094,560,256
7May 26, 2021 18:185,10173,992,20828,256,00018,165,00094,793,728
8May 26, 2021 18:185,116125,478,05846,556,227094,674,944
9May 26, 2021 18:185,15773,808,41036,943,0009,984,00093,134,848
10May 26, 2021 18:185,25973,752,70932,903,00014,956,00092,872,704
11May 26, 2021 18:185,31271,051,16933,232,00015,105,00094,560,256
12May 26, 2021 18:185,34277,257,18828,356,00020,254,00094,560,256