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 listMay 22, 2024 01:47Joad NacerJoad NacerScore: 3,669Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 01:473,41660,780,84322,058,0009,024,00093,134,848
2May 22, 2024 01:473,43354,593,70220,157,00011,086,00092,905,472
3May 22, 2024 01:473,44958,923,65420,252,00011,138,00092,934,144
4May 22, 2024 01:473,52052,247,65620,019,00012,011,00093,003,776
5May 22, 2024 01:473,53558,250,87920,108,00012,065,00092,946,432
6May 22, 2024 01:473,666102,345,35133,361,142094,482,432
7May 22, 2024 01:473,669106,908,94033,388,907094,605,312
8May 22, 2024 01:473,69298,648,29033,594,296094,617,600
9May 22, 2024 01:474,01067,631,00120,272,00016,217,00093,134,848
10May 22, 2024 01:477,41690,568,16024,174,00043,311,00093,122,560
11May 22, 2024 01:477,50291,178,56126,101,00042,164,00093,286,400
12May 22, 2024 01:477,52691,184,70525,178,00043,306,00093,233,152