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 listJul 28, 2023 22:12Yurkov AlekseyYurkov AlekseyScore: 10,890Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 28, 2023 22:127,785127,284,16770,843,120092,569,600
2Jul 28, 2023 22:127,791131,651,01170,896,348092,565,504
3Jul 28, 2023 22:127,836125,716,09471,306,837092,565,504
4Jul 28, 2023 22:1210,853122,243,27980,805,00017,956,00092,471,296
5Jul 28, 2023 22:1210,882123,152,87582,019,00017,004,00092,471,296
6Jul 28, 2023 22:1210,887121,271,16780,060,00019,014,00092,704,768
7Jul 28, 2023 22:1210,890124,369,37682,084,00017,017,00092,553,216
8Jul 28, 2023 22:1210,893127,705,82479,100,00020,025,00092,459,008
9Jul 28, 2023 22:1210,905126,772,76579,189,00020,048,00092,463,104
10Jul 28, 2023 22:1210,906125,468,52480,196,00019,046,00092,708,864
11Jul 28, 2023 22:1211,186130,732,62779,840,00021,956,00092,192,768
12Jul 28, 2023 22:1211,239127,098,91883,226,00019,051,00092,200,960