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 listNov 29, 2024 14:21E SequeiraE SequeiraScore: 939,713Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Nov 29, 2024 14:21935,1558,546,195,2648,452,964,00056,945,00094,564,352
2Nov 29, 2024 14:21936,9158,565,788,9578,471,989,00053,942,00094,621,696
3Nov 29, 2024 14:21937,9018,568,557,0818,489,935,00044,962,00094,810,112
4Nov 29, 2024 14:21937,9508,573,442,0528,486,389,00048,956,00094,588,928
5Nov 29, 2024 14:21939,7138,583,944,5398,503,441,00047,951,00094,806,016
6Nov 29, 2024 14:21940,1438,588,536,8788,515,344,00039,959,00094,572,544
7Nov 29, 2024 14:21945,8978,644,074,4888,554,712,00052,948,00094,588,928
8Nov 29, 2024 14:21946,5878,649,913,8398,540,005,00073,939,00094,601,216
9Nov 29, 2024 14:21948,8378,673,446,1278,580,456,00053,958,00094,593,024