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 11:28Mikhail ShirokovMikhail ShirokovScore: 9,852Success
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 11:289,830118,346,33780,409,0009,046,000103,141,376
2Jan 11, 2025 11:289,833112,590,32679,430,00010,054,000103,124,992
3Jan 11, 2025 11:289,840116,832,54080,491,0009,055,000103,170,048
4Jan 11, 2025 11:289,845116,036,99680,635,0008,959,000103,157,760
5Jan 11, 2025 11:289,852113,447,79577,698,00011,953,000103,215,104
6Jan 11, 2025 11:289,853113,575,81578,705,00010,958,000103,260,160
7Jan 11, 2025 11:289,860116,785,82178,756,00010,966,000103,034,880
8Jan 11, 2025 11:289,872123,367,24177,860,00011,978,000103,182,336
9Jan 11, 2025 11:289,876118,413,91978,891,00010,984,000103,112,704