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 30, 2024 16:04Mikhail ShirokovMikhail ShirokovScore: 45,350Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 30, 2024 16:0445,266437,072,663321,940,00089,983,000111,386,624
2Dec 30, 2024 16:0445,307441,169,771324,233,00088,063,000111,349,760
3Dec 30, 2024 16:0445,320440,461,077321,540,00090,870,000111,386,624
4Dec 30, 2024 16:0445,343439,173,098312,712,00099,908,000111,464,448
5Dec 30, 2024 16:0445,350434,842,305317,760,00094,928,000111,349,760
6Dec 30, 2024 16:0445,360438,040,801320,823,00091,949,000111,443,968
7Dec 30, 2024 16:0445,363438,053,984323,845,00088,957,000111,554,560
8Dec 30, 2024 16:0445,395445,128,266319,070,00094,020,000111,403,008
9Dec 30, 2024 16:0445,525443,815,064315,213,00099,067,000111,370,240