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 listApr 22, 2024 00:25Joad NacerJoad NacerScore: 4,042Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 00:253,96965,884,72325,084,00011,037,00093,024,256
2Apr 22, 2024 00:253,99161,289,20425,221,00011,097,00093,126,656
3Apr 22, 2024 00:254,00863,393,60726,341,00010,131,00092,942,336
4Apr 22, 2024 00:254,00956,225,47925,337,00011,148,00092,962,816
5Apr 22, 2024 00:254,01362,681,00725,361,00011,159,00092,835,840
6Apr 22, 2024 00:254,01457,927,43125,367,00011,161,00092,893,184
7Apr 22, 2024 00:254,04264,028,43525,844,00010,934,00092,860,416
8Apr 22, 2024 00:254,18497,687,17838,071,904094,486,528
9Apr 22, 2024 00:254,19497,837,72338,161,024094,486,528
10Apr 22, 2024 00:254,21498,009,80338,344,692094,482,432
11Apr 22, 2024 00:254,24562,369,64324,763,00013,867,00092,971,008
12Apr 22, 2024 00:254,92375,444,75524,888,00019,910,00093,179,904