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:14Mikhail ShirokovMikhail ShirokovScore: 38,870Success
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:1438,687377,934,295294,046,00058,009,000111,427,584
2Dec 30, 2024 16:1438,851377,134,598298,617,00054,929,000111,501,312
3Dec 30, 2024 16:1438,853377,140,351300,628,00052,934,000111,370,240
4Dec 30, 2024 16:1438,853384,965,867293,640,00059,926,000111,575,040
5Dec 30, 2024 16:1438,870382,738,895300,759,00052,957,000111,435,776
6Dec 30, 2024 16:1438,871385,612,312296,767,00056,955,000111,398,912
7Dec 30, 2024 16:1438,918381,795,707298,132,00056,024,000111,546,368
8Dec 30, 2024 16:1439,053381,427,454291,314,00064,069,000111,566,848
9Dec 30, 2024 16:1439,179386,605,074298,609,00057,924,000111,345,664