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:46Joad NacerJoad NacerScore: 4,205Success
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:463,99559,392,57725,247,00011,108,00092,876,800
2May 21, 2024 23:464,02861,970,56924,768,00011,888,00093,151,232
3May 21, 2024 23:464,04762,357,13424,882,00011,943,00092,925,952
4May 21, 2024 23:464,05569,031,98124,934,00011,968,00092,893,184
5May 21, 2024 23:464,07461,849,22425,049,00012,023,00092,884,992
6May 21, 2024 23:464,182104,534,27938,059,789094,482,432
7May 21, 2024 23:464,20563,158,00927,188,00011,076,00093,163,520
8May 21, 2024 23:464,206108,880,25338,272,721094,498,816
9May 21, 2024 23:464,211104,267,24238,323,737094,478,336
10May 21, 2024 23:467,45494,198,58527,930,00039,900,00093,265,920
11May 21, 2024 23:467,59099,058,41729,031,00040,042,00093,253,632
12May 21, 2024 23:468,068101,123,53229,168,00044,255,00093,200,384