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 17:14AnSaAnSaScore: 4,364Success
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 17:143,63064,016,57120,018,00013,011,00092,577,792
2Jun 24, 2024 17:143,64360,485,75720,091,00013,059,00092,680,192
3Jun 24, 2024 17:143,66561,994,16221,224,00012,128,00092,598,272
4Jun 24, 2024 17:144,17664,796,25319,001,00019,001,00092,856,320
5Jun 24, 2024 17:144,20265,335,99118,112,00020,124,00092,614,656
6Jun 24, 2024 17:144,28664,489,77119,001,00020,001,00092,876,800
7Jun 24, 2024 17:144,364100,449,89339,715,929094,621,696
8Jun 24, 2024 17:144,36892,195,34239,748,499094,617,600
9Jun 24, 2024 17:144,408112,168,47240,113,118094,625,792
10Jun 24, 2024 17:148,317100,815,77026,887,00048,796,00092,942,336
11Jun 24, 2024 17:148,386101,431,97425,103,00051,211,00092,950,528
12Jun 24, 2024 17:148,411101,613,75726,183,00050,353,00092,934,144