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 listJun 23, 2024 16:38AnSaAnSaScore: 4,639Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 23, 2024 16:383,85261,429,66127,038,0008,011,00091,881,472
2Jun 23, 2024 16:383,85265,775,00918,028,00017,027,00091,947,008
3Jun 23, 2024 16:383,90056,262,77426,367,0009,127,00092,061,696
4Jun 23, 2024 16:384,25061,883,17622,811,00015,868,00092,160,000
5Jun 23, 2024 16:384,60466,356,91724,940,00016,959,00092,160,000
6Jun 23, 2024 16:384,621105,551,01242,048,206092,524,544
7Jun 23, 2024 16:384,63996,901,19142,215,015092,528,640
8Jun 23, 2024 16:384,651111,635,25042,328,217092,778,496
9Jun 23, 2024 16:384,72174,264,86321,979,00020,980,00092,127,232
10Jun 23, 2024 16:388,576103,588,28925,012,00053,026,00092,262,400
11Jun 23, 2024 16:388,653104,141,86531,897,00046,849,00092,364,800
12Jun 23, 2024 16:388,655102,826,12728,914,00049,851,00092,426,240