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 12, 2024 00:44Joad NacerJoad NacerScore: 4,261Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 12, 2024 00:443,59358,785,02020,807,00011,889,00092,897,280
2May 12, 2024 00:443,59764,853,66321,823,00010,911,00092,930,048
3May 12, 2024 00:443,62362,330,56520,983,00011,990,00092,925,952
4May 12, 2024 00:443,74996,086,85234,119,629094,498,816
5May 12, 2024 00:443,77699,327,70434,359,534094,490,624
6May 12, 2024 00:443,787101,651,47334,460,947094,494,720
7May 12, 2024 00:444,26165,663,02221,873,00016,902,00093,188,096
8May 12, 2024 00:444,46768,689,90522,357,00018,292,00093,138,944
9May 12, 2024 00:445,07668,980,82323,096,00023,096,00093,229,056
10May 12, 2024 00:447,60395,520,51826,072,00043,119,00093,302,784
11May 12, 2024 00:447,65699,721,23226,871,00042,795,00093,216,768
12May 12, 2024 00:447,67496,216,48926,935,00042,896,00093,143,040