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 listJan 11, 2025 10:57Mikhail ShirokovMikhail ShirokovScore: 9,966Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jan 11, 2025 10:579,944123,441,41181,444,0009,049,000103,133,184
2Jan 11, 2025 10:579,948122,061,10281,472,0009,052,000103,084,032
3Jan 11, 2025 10:579,959123,318,49981,665,0008,963,000103,055,360
4Jan 11, 2025 10:579,966116,996,03381,719,0008,969,000103,313,408
5Jan 11, 2025 10:579,966116,970,56180,727,0009,966,000103,100,416
6Jan 11, 2025 10:579,969120,791,38879,752,00010,966,000103,174,144
7Jan 11, 2025 10:579,972115,666,67579,775,00010,969,000103,116,800
8Jan 11, 2025 10:579,973119,782,65383,773,0006,981,000103,219,200
9Jan 11, 2025 10:579,981119,630,00279,846,00010,978,000102,985,728