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 12, 2024 00:37Joad NacerJoad NacerScore: 3,766Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 12, 2024 00:373,56753,596,81322,316,00010,143,00092,835,840
2May 12, 2024 00:373,57265,615,31322,347,00010,157,00092,917,760
3May 12, 2024 00:373,59563,094,35421,810,00010,905,00092,954,624
4May 12, 2024 00:373,61265,211,04520,918,00011,953,00092,958,720
5May 12, 2024 00:373,61756,482,65520,944,00011,968,00093,151,232
6May 12, 2024 00:373,76299,410,96334,231,835094,486,528
7May 12, 2024 00:373,76695,026,46834,271,609094,494,720
8May 12, 2024 00:373,78189,164,06834,403,300094,482,432
9May 12, 2024 00:374,14465,761,53022,823,00014,884,00093,175,808
10May 12, 2024 00:376,16684,441,06125,051,00031,064,00093,216,768
11May 12, 2024 00:377,31394,876,58125,207,00041,340,00093,208,576
12May 12, 2024 00:377,50192,974,41126,098,00042,159,00093,175,808