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 10, 2024 00:46Joad NacerJoad NacerScore: 3,798Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 10, 2024 00:463,57755,128,16922,378,00010,171,00092,921,856
2May 10, 2024 00:463,58162,534,58123,423,0009,165,00092,889,088
3May 10, 2024 00:463,58462,637,54822,421,00010,191,00092,909,568
4May 10, 2024 00:463,60657,754,00520,882,00011,933,00092,901,376
5May 10, 2024 00:463,61061,352,12121,561,00011,294,00092,889,088
6May 10, 2024 00:463,79091,280,39034,485,359094,498,816
7May 10, 2024 00:463,798104,516,76634,561,016094,486,528
8May 10, 2024 00:463,832107,730,80834,867,405094,494,720
9May 10, 2024 00:464,15962,507,57722,906,00014,938,00093,106,176
10May 10, 2024 00:466,95289,105,30026,107,00037,152,00093,274,112
11May 10, 2024 00:467,433102,291,70725,238,00042,400,00093,200,384
12May 10, 2024 00:467,671100,695,49825,928,00043,879,00093,163,520