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 02:58Joad NacerJoad NacerScore: 4,012Success
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 02:583,79566,161,16224,380,00010,158,00092,893,184
2Apr 22, 2024 02:583,85064,028,19924,026,00011,011,00092,913,664
3Apr 22, 2024 02:583,87357,725,82323,163,00012,085,00092,921,856
4Apr 22, 2024 02:583,87464,763,95223,166,00012,087,00092,856,320
5Apr 22, 2024 02:583,986108,733,89636,276,120094,490,624
6Apr 22, 2024 02:583,988106,250,06036,292,429094,490,624
7Apr 22, 2024 02:584,012100,521,27736,506,290094,490,624
8Apr 22, 2024 02:584,18865,478,07624,068,00014,040,00093,163,520
9Apr 22, 2024 02:584,34566,022,45325,348,00014,195,00093,143,040
10Apr 22, 2024 02:586,93892,034,97428,059,00035,074,00093,261,824
11Apr 22, 2024 02:587,23197,576,52626,918,00038,882,00093,270,016
12Apr 22, 2024 02:587,75099,935,97028,210,00042,315,00093,253,632