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 31, 2024 07:38Mikhail ShirokovMikhail ShirokovScore: 18,443Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 31, 2024 07:3818,412201,798,591112,366,00055,179,000105,107,456
2Dec 31, 2024 07:3818,415196,054,056103,738,00063,839,000105,123,840
3Dec 31, 2024 07:3818,422195,514,021111,760,00055,880,000105,271,296
4Dec 31, 2024 07:3818,441195,207,298109,876,00057,935,000105,091,072
5Dec 31, 2024 07:3818,443200,761,906117,881,00049,949,000105,177,088
6Dec 31, 2024 07:3818,444193,694,955108,894,00058,943,000105,250,816
7Dec 31, 2024 07:3818,473197,873,089114,069,00054,032,000105,136,128
8Dec 31, 2024 07:3818,476197,928,604113,086,00055,042,000105,066,496
9Dec 31, 2024 07:3818,507198,032,273118,293,00050,124,000105,123,840