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 27, 2024 20:00Joad NacerJoad NacerScore: 3,390Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 20:003,16962,572,17217,902,00010,940,00092,966,912
2Jul 27, 2024 20:003,22560,035,96720,243,0009,109,00093,122,560
3Jul 27, 2024 20:003,23348,092,70820,287,0009,129,00093,052,928
4Jul 27, 2024 20:003,23754,848,29919,297,00010,156,00093,069,312
5Jul 27, 2024 20:003,24562,318,67720,367,0009,165,00092,889,088
6Jul 27, 2024 20:003,26058,597,65218,789,00010,878,00092,917,760
7Jul 27, 2024 20:003,390101,425,17930,844,451094,507,008
8Jul 27, 2024 20:003,39298,572,19030,871,270094,494,720
9Jul 27, 2024 20:003,40684,837,33930,996,568094,502,912
10Jul 27, 2024 20:003,87558,543,70520,151,00015,113,00093,011,968
11Jul 27, 2024 20:005,52875,231,10821,129,00029,179,00093,200,384
12Jul 27, 2024 20:006,84887,667,14323,119,00039,202,00093,229,056