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 22, 2024 01:26Joad NacerJoad NacerScore: 3,764Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 22, 2024 01:263,46251,808,91821,340,00010,162,00092,934,144
2May 22, 2024 01:263,46658,554,46921,365,00010,174,00093,003,776
3May 22, 2024 01:263,54454,480,82020,157,00012,094,00092,901,376
4May 22, 2024 01:263,55257,354,92521,213,00011,111,00092,893,184
5May 22, 2024 01:263,56356,087,68521,276,00011,144,00092,876,800
6May 22, 2024 01:263,76199,033,96434,225,463094,486,528
7May 22, 2024 01:263,764107,851,30134,252,284094,613,504
8May 22, 2024 01:263,786109,132,64134,455,535094,490,624
9May 22, 2024 01:265,21074,982,66023,201,00024,210,00093,114,368
10May 22, 2024 01:266,48093,640,70423,988,00034,982,00093,278,208
11May 22, 2024 01:267,36095,306,97423,992,00042,986,00093,245,440
12May 22, 2024 01:267,59191,001,30025,027,00044,048,00093,167,616