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 06:52Mikhail ShirokovMikhail ShirokovScore: 18,493Success
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 06:5218,404195,067,902117,333,00050,142,000105,168,896
2Dec 31, 2024 06:5218,470195,856,708116,056,00052,025,000105,115,648
3Dec 31, 2024 06:5218,471196,094,149109,057,00059,030,000105,164,800
4Dec 31, 2024 06:5218,485189,593,594111,138,00057,071,000105,193,472
5Dec 31, 2024 06:5218,493206,139,691114,192,00054,091,000105,050,112
6Dec 31, 2024 06:5218,526196,727,253116,713,00051,872,000105,299,968
7Dec 31, 2024 06:5218,531188,982,620111,759,00056,877,000105,082,880
8Dec 31, 2024 06:5218,533195,076,818117,754,00050,893,000105,168,896
9Dec 31, 2024 06:5218,561188,425,681117,936,00050,972,000105,295,872