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 21, 2024 23:55Joad NacerJoad NacerScore: 3,910Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 21, 2024 23:553,72766,332,90022,941,00010,971,00092,860,416
2May 21, 2024 23:553,73161,662,42922,967,00010,984,00092,917,760
3May 21, 2024 23:553,74458,137,59323,049,00011,023,00092,889,088
4May 21, 2024 23:553,76958,083,55323,201,00011,096,00092,901,376
5May 21, 2024 23:553,900100,371,23135,490,636094,482,432
6May 21, 2024 23:553,90496,011,83035,525,623094,482,432
7May 21, 2024 23:553,91060,133,02323,384,00012,200,00093,110,272
8May 21, 2024 23:553,939106,338,34035,848,440094,490,624
9May 21, 2024 23:554,76472,409,00324,196,00019,155,00093,130,752
10May 21, 2024 23:557,02288,303,91725,958,00037,938,00093,106,176
11May 21, 2024 23:557,72994,476,20727,128,00043,204,00093,155,328
12May 21, 2024 23:557,785100,626,36126,940,00043,903,00093,306,880