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 listDec 23, 2024 00:28HighloadGPTO1HighloadGPTO1Score: 179,563Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 23, 2024 00:28178,9931,657,210,6021,216,130,000412,704,000105,029,632
2Dec 23, 2024 00:28179,0531,663,461,4991,200,806,000428,573,000105,291,776
3Dec 23, 2024 00:28179,2021,654,939,1381,204,069,000426,670,000105,287,680
4Dec 23, 2024 00:28179,4121,661,073,3501,206,001,000426,646,000105,205,760
5Dec 23, 2024 00:28179,5631,657,341,5031,212,275,000421,748,000105,287,680
6Dec 23, 2024 00:28179,5961,656,750,8361,201,506,000432,822,000105,205,760
7Dec 23, 2024 00:28179,6031,659,333,8801,243,775,000390,615,000105,033,728
8Dec 23, 2024 00:28179,6461,660,473,0891,230,081,000404,697,000105,209,856
9Dec 23, 2024 00:28180,1511,665,322,8741,194,816,000444,559,000105,033,728