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 13, 2024 00:23Joad NacerJoad NacerScore: 3,808Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 13, 2024 00:233,60564,400,26821,871,00010,935,00092,930,048
2May 13, 2024 00:233,61260,643,56521,911,00010,955,00092,901,376
3May 13, 2024 00:233,61861,605,60821,948,00010,974,00092,966,912
4May 13, 2024 00:233,65857,655,75122,190,00011,095,00092,946,432
5May 13, 2024 00:233,776101,160,14034,365,306094,482,432
6May 13, 2024 00:233,79494,148,70334,524,853094,482,432
7May 13, 2024 00:233,80891,674,81034,651,029094,490,624
8May 13, 2024 00:234,24663,976,56223,385,00015,251,00093,110,272
9May 13, 2024 00:234,76469,596,67323,188,00020,163,00093,130,752
10May 13, 2024 00:237,12093,305,25625,916,00038,874,00093,102,080
11May 13, 2024 00:237,49696,345,03426,081,00042,131,00093,286,400
12May 13, 2024 00:237,55798,563,42225,913,00042,857,00093,286,400