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:39Mikhail ShirokovMikhail ShirokovScore: 23,298Success
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:3923,209237,069,528150,147,00061,059,000105,046,016
2Dec 31, 2024 06:3923,270237,756,834157,821,00053,939,000105,037,824
3Dec 31, 2024 06:3923,276239,385,723152,864,00058,947,000105,263,104
4Dec 31, 2024 06:3923,287238,705,206157,936,00053,978,000105,250,816
5Dec 31, 2024 06:3923,298243,629,355156,007,00056,002,000105,046,016
6Dec 31, 2024 06:3923,303240,510,809154,044,00058,016,000105,054,208
7Dec 31, 2024 06:3923,318234,153,689151,139,00061,056,000105,230,336
8Dec 31, 2024 06:3923,363245,293,585148,721,00063,880,000105,193,472
9Dec 31, 2024 06:3923,365239,298,700158,715,00053,903,000105,033,728