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:19AnSaAnSaScore: 7,215Success
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:194,33460,688,52726,292,00013,146,00091,955,200
2Jun 23, 2024 16:194,35764,819,56726,762,00012,885,00092,160,000
3Jun 23, 2024 16:194,36563,390,69726,813,00012,910,00092,041,216
4Jun 23, 2024 16:194,37764,796,94927,885,00011,950,00091,918,336
5Jun 23, 2024 16:194,92578,540,78626,890,00017,927,00091,918,336
6Jun 23, 2024 16:195,07074,368,43527,078,00019,055,00092,147,712
7Jun 23, 2024 16:197,215138,262,42065,653,749092,528,640
8Jun 23, 2024 16:197,224116,854,37465,734,298092,524,544
9Jun 23, 2024 16:197,289127,160,00466,333,969092,524,544
10Jun 23, 2024 16:197,49089,548,07030,070,00038,089,00092,303,360
11Jun 23, 2024 16:199,219113,879,31136,954,00046,941,00092,262,400
12Jun 23, 2024 16:199,270110,168,89936,152,00048,202,00092,250,112