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 31, 2024 07:44Mikhail ShirokovMikhail ShirokovScore: 18,060Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 31, 2024 07:4417,999192,037,195109,859,00053,931,000105,127,936
2Dec 31, 2024 07:4418,020192,544,828109,988,00053,994,000105,226,240
3Dec 31, 2024 07:4418,053198,127,085106,537,00057,749,000105,295,872
4Dec 31, 2024 07:4418,054189,860,450117,205,00047,082,000105,099,264
5Dec 31, 2024 07:4418,060190,149,112113,241,00051,108,000105,086,976
6Dec 31, 2024 07:4418,100194,359,432103,815,00060,891,000105,136,128
7Dec 31, 2024 07:4418,102188,552,802118,803,00045,924,000105,177,088
8Dec 31, 2024 07:4418,111190,584,055113,870,00050,941,000105,201,664
9Dec 31, 2024 07:4418,137186,292,252110,033,00055,016,000105,086,976