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 10, 2024 00:44Joad NacerJoad NacerScore: 3,784Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 10, 2024 00:443,56361,497,83522,293,00010,133,00092,962,816
2May 10, 2024 00:443,57861,316,16922,384,00010,174,00092,893,184
3May 10, 2024 00:443,58361,092,41822,418,00010,190,00092,860,416
4May 10, 2024 00:443,60257,527,58120,856,00011,918,00093,114,368
5May 10, 2024 00:443,62362,726,48520,979,00011,988,00092,934,144
6May 10, 2024 00:443,62462,309,85721,985,00010,992,00092,884,992
7May 10, 2024 00:443,78492,317,19034,436,571094,490,624
8May 10, 2024 00:443,78597,784,21834,441,106094,486,528
9May 10, 2024 00:443,807106,347,57834,646,737094,490,624
10May 10, 2024 00:444,91972,511,23022,880,00021,885,00093,073,408
11May 10, 2024 00:446,80486,902,19825,964,00035,950,00093,065,216
12May 10, 2024 00:447,19497,041,79125,177,00040,284,00093,278,208