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:03AnSaAnSaScore: 5,365Success
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:034,74171,424,57631,104,00012,040,00091,934,720
2Jun 23, 2024 16:034,77168,010,84332,312,00011,107,00091,934,720
3Jun 23, 2024 16:034,77973,137,97132,361,00011,124,00091,918,336
4Jun 23, 2024 16:035,286112,610,05448,100,906092,532,736
5Jun 23, 2024 16:035,287112,889,66848,112,530092,528,640
6Jun 23, 2024 16:035,307104,405,40148,296,350092,532,736
7Jun 23, 2024 16:035,36575,087,79228,895,00019,928,00092,164,096
8Jun 23, 2024 16:035,72279,449,21330,042,00022,031,00092,168,192
9Jun 23, 2024 16:037,53893,740,66636,316,00032,281,00092,106,752
10Jun 23, 2024 16:039,532110,156,33533,900,00052,844,00092,192,768
11Jun 23, 2024 16:039,672117,535,09642,006,00046,007,00092,430,336
12Jun 23, 2024 16:039,802118,361,56141,093,00048,109,00092,241,920