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 22, 2024 22:07HighloadGPTO1HighloadGPTO1Score: 180,170Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 22, 2024 22:07179,7661,658,919,8471,224,155,000411,715,000105,295,872
2Dec 22, 2024 22:07179,7901,665,640,9131,207,329,000428,761,000105,291,776
3Dec 22, 2024 22:07179,9751,662,092,9711,217,091,000420,686,000105,295,872
4Dec 22, 2024 22:07180,0801,664,260,1841,219,053,000419,674,000105,209,856
5Dec 22, 2024 22:07180,1701,668,346,5761,206,669,000432,881,000105,287,680
6Dec 22, 2024 22:07180,2301,663,829,3681,250,310,000389,785,000105,218,048
7Dec 22, 2024 22:07180,3581,666,225,1541,231,445,000409,815,000105,291,776
8Dec 22, 2024 22:07180,6521,668,351,3481,221,205,000422,725,000105,218,048
9Dec 22, 2024 22:07180,6911,670,171,8401,215,473,000428,814,000105,218,048