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 9, 2024 23:10Joad NacerJoad NacerScore: 4,274Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 9, 2024 23:104,08266,600,02227,105,00010,039,00092,921,856
2May 9, 2024 23:104,13065,079,19427,423,00010,156,00092,950,528
3May 9, 2024 23:104,15066,136,25226,836,00010,933,00092,901,376
4May 9, 2024 23:104,15367,276,06025,859,00011,935,00092,930,048
5May 9, 2024 23:104,26266,966,20826,851,00011,934,00092,962,816
6May 9, 2024 23:104,27392,656,49838,881,139094,494,720
7May 9, 2024 23:104,27497,031,23238,889,952094,478,336
8May 9, 2024 23:104,299107,922,61039,121,049094,490,624
9May 9, 2024 23:105,56777,286,70126,821,00023,841,00093,073,408
10May 9, 2024 23:106,66086,018,75930,302,00030,302,00093,310,976
11May 9, 2024 23:107,996104,999,05628,905,00043,855,00093,347,840
12May 9, 2024 23:108,003100,507,30829,928,00042,896,00093,282,304