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:19Mikhail ShirokovMikhail ShirokovScore: 27,995Success
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:1927,968280,782,689201,614,00052,898,000105,144,320
2Dec 31, 2024 06:1927,981284,120,110202,704,00051,924,000105,046,016
3Dec 31, 2024 06:1927,984283,870,705211,711,00042,941,000105,119,744
4Dec 31, 2024 06:1927,989283,491,115196,766,00057,931,000105,218,048
5Dec 31, 2024 06:1927,995284,919,471203,807,00050,951,000105,054,208
6Dec 31, 2024 06:1928,002283,066,391194,863,00059,958,000105,172,992
7Dec 31, 2024 06:1928,033278,709,988203,082,00052,021,000105,074,688
8Dec 31, 2024 06:1928,053282,851,031205,230,00050,056,000105,242,624
9Dec 31, 2024 06:1928,129280,474,609201,983,00053,995,000105,259,008