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:47Mikhail ShirokovMikhail ShirokovScore: 10,255Success
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:4710,232118,281,63382,098,00011,013,000103,211,008
2Jan 11, 2025 10:4710,243118,535,78584,191,0009,020,000103,055,360
3Jan 11, 2025 10:4710,250113,700,46282,239,00011,032,000103,038,976
4Jan 11, 2025 10:4710,250115,411,31185,254,0008,023,000103,206,912
5Jan 11, 2025 10:4710,255111,074,39985,294,0008,027,000103,079,936
6Jan 11, 2025 10:4710,257119,915,42285,308,0008,029,000103,186,432
7Jan 11, 2025 10:4710,261118,289,62984,342,0009,036,000103,297,024
8Jan 11, 2025 10:4710,264125,315,74283,357,00010,043,000103,292,928
9Jan 11, 2025 10:4710,291117,697,13185,682,0007,970,000103,272,448