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 listOct 31, 2021 14:08Ilya AniskovetsIlya AniskovetsScore: 9,794Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Oct 31, 2021 14:089,726117,895,94343,248,00045,259,00094,584,832
2Oct 31, 2021 14:089,746117,153,37444,844,00043,847,00094,789,632
3Oct 31, 2021 14:089,750115,714,63837,883,00050,843,00094,576,640
4Oct 31, 2021 14:089,760115,604,89738,921,00049,899,00094,564,352
5Oct 31, 2021 14:089,765117,014,91038,371,00050,489,00094,781,440
6Oct 31, 2021 14:089,769112,129,24140,952,00047,944,00094,547,968
7Oct 31, 2021 14:089,794115,958,93043,060,00046,064,00094,613,504
8Oct 31, 2021 14:089,809113,667,75737,107,00052,151,00093,024,256
9Oct 31, 2021 14:089,841118,667,10740,247,00049,302,00092,962,816
10Oct 31, 2021 14:0810,128169,413,47592,161,203094,748,672
11Oct 31, 2021 14:0810,133148,552,45892,206,995094,777,344
12Oct 31, 2021 14:0810,165159,029,26392,504,412094,683,136