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 12, 2024 00:41Joad NacerJoad NacerError
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 12, 2024 00:4100000Error: unexpected EOF
2May 12, 2024 00:413,56560,295,35122,306,00010,139,00092,938,240
3May 12, 2024 00:413,57561,511,62322,367,00010,166,00092,901,376
4May 12, 2024 00:413,60955,616,60020,901,00011,943,00092,921,856
5May 12, 2024 00:413,62263,933,75820,975,00011,986,00092,938,240
6May 12, 2024 00:413,77092,139,24734,305,452094,486,528
7May 12, 2024 00:413,77896,705,29534,375,941094,752,768
8May 12, 2024 00:413,793100,969,48634,516,141094,482,432
9May 12, 2024 00:413,88856,622,62622,240,00013,142,00092,889,088
10May 12, 2024 00:415,00771,621,99924,302,00021,265,00093,073,408
11May 12, 2024 00:416,95288,068,39025,700,00037,562,00093,003,776
12May 12, 2024 00:417,01389,835,96226,925,00036,897,00093,339,648
13May 12, 2024 00:417,69998,932,41626,024,00044,041,00093,286,400