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:40Joad NacerJoad NacerScore: 3,753Success
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:403,49761,874,03121,556,00010,264,00093,159,424
2May 21, 2024 23:403,50658,155,31920,937,00010,967,00092,913,664
3May 21, 2024 23:403,54854,402,87820,180,00012,108,00092,901,376
4May 21, 2024 23:403,55558,199,74520,217,00012,130,00092,856,320
5May 21, 2024 23:403,56355,006,42621,276,00011,144,00092,889,088
6May 21, 2024 23:403,72575,671,42033,895,114094,478,336
7May 21, 2024 23:403,75397,030,69334,149,161094,494,720
8May 21, 2024 23:403,76087,918,41534,220,513094,482,432
9May 21, 2024 23:404,09066,569,88221,123,00016,094,00093,118,464
10May 21, 2024 23:406,57385,610,19325,920,00033,896,00093,175,808
11May 21, 2024 23:407,14588,361,98125,006,00040,010,00093,097,984
12May 21, 2024 23:407,58397,850,57425,003,00044,006,00093,323,264