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 15:23Mikhail ShirokovMikhail ShirokovScore: 46,150Success
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 15:2346,015445,870,028327,793,00090,942,000111,357,952
2Dec 30, 2024 15:2346,067444,765,559332,166,00087,043,000111,472,640
3Dec 30, 2024 15:2346,082448,424,506324,491,00094,851,000111,325,184
4Dec 30, 2024 15:2346,091450,272,584333,545,00085,882,000111,411,200
5Dec 30, 2024 15:2346,150447,386,840322,970,00096,991,000111,370,240
6Dec 30, 2024 15:2346,156447,013,297321,018,00099,005,000111,546,368
7Dec 30, 2024 15:2346,157440,584,154319,025,000101,008,000111,525,888
8Dec 30, 2024 15:2346,194453,432,251328,504,00091,861,000111,357,952
9Dec 30, 2024 15:2346,412448,535,524338,475,00083,870,000111,558,656