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 24, 2024 16:56AnSaAnSaScore: 6,390Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 24, 2024 16:563,69660,684,95521,761,00011,870,00092,114,944
2Jun 24, 2024 16:563,72664,121,30223,935,0009,973,00092,102,656
3Jun 24, 2024 16:563,74958,580,62221,071,00013,044,00092,110,848
4Jun 24, 2024 16:564,20165,084,35720,120,00018,108,00092,360,704
5Jun 24, 2024 16:564,27766,041,56922,955,00015,968,00092,356,608
6Jun 24, 2024 16:565,09176,183,69624,172,00022,157,00092,200,960
7Jun 24, 2024 16:566,390125,102,22858,151,931092,520,448
8Jun 24, 2024 16:566,430123,369,80558,509,797092,520,448
9Jun 24, 2024 16:566,437118,852,88458,580,196092,524,544
10Jun 24, 2024 16:568,164100,564,73328,111,00046,183,00092,463,104
11Jun 24, 2024 16:568,42599,372,95926,884,00049,785,00092,450,816
12Jun 24, 2024 16:568,436100,925,17829,909,00046,858,00092,536,832