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:19Joad NacerJoad NacerScore: 4,030Success
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:193,82060,324,44923,840,00010,926,00092,909,568
2Apr 22, 2024 00:193,82460,447,45323,862,00010,936,00092,856,320
3Apr 22, 2024 00:193,82559,624,88724,863,0009,945,00092,913,664
4Apr 22, 2024 00:193,86554,774,59924,120,00011,055,00092,893,184
5Apr 22, 2024 00:193,88860,799,60424,263,00011,120,00092,893,184
6Apr 22, 2024 00:193,89159,467,76525,294,00010,117,00092,864,512
7Apr 22, 2024 00:194,03095,461,66836,676,194094,490,624
8Apr 22, 2024 00:194,042111,396,33036,785,681094,482,432
9Apr 22, 2024 00:194,053123,562,74936,882,519094,482,432
10Apr 22, 2024 00:194,06863,712,21424,010,00013,005,00092,971,008
11Apr 22, 2024 00:194,15462,707,17923,873,00013,926,00092,950,528
12Apr 22, 2024 00:194,36269,019,15224,807,00014,884,00092,889,088