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 21, 2024 23:59Joad NacerJoad NacerScore: 4,198Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 21, 2024 23:594,07962,436,26926,084,00011,035,00092,913,664
2Apr 21, 2024 23:594,08359,805,42426,111,00011,047,00093,024,256
3Apr 21, 2024 23:594,12266,844,93827,375,00010,139,00092,909,568
4Apr 21, 2024 23:594,14766,589,58225,819,00011,916,00092,864,512
5Apr 21, 2024 23:594,15665,381,01825,874,00011,942,00092,901,376
6Apr 21, 2024 23:594,17168,838,21925,972,00011,987,00092,950,528
7Apr 21, 2024 23:594,19868,564,96426,136,00012,063,00092,925,952
8Apr 21, 2024 23:594,587114,558,99241,740,717094,494,720
9Apr 21, 2024 23:594,595109,852,79341,818,564094,486,528
10Apr 21, 2024 23:594,618119,957,73142,026,594094,494,720
11Apr 21, 2024 23:594,74877,210,50927,130,00016,077,00092,946,432
12Apr 21, 2024 23:595,09675,140,16627,221,00019,156,00093,196,288