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 listJul 28, 2023 23:20Yurkov AlekseyYurkov AlekseyScore: 17,161Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 28, 2023 23:2010,041163,141,55691,370,375092,581,888
2Jul 28, 2023 23:2010,060148,712,10691,545,915092,684,288
3Jul 28, 2023 23:2010,081157,947,78491,739,084092,672,000
4Jul 28, 2023 23:2017,128180,258,807107,906,00047,958,00092,483,584
5Jul 28, 2023 23:2017,152182,821,655103,053,00053,027,00092,483,584
6Jul 28, 2023 23:2017,156179,129,417112,088,00044,034,00092,520,448
7Jul 28, 2023 23:2017,161177,817,468106,115,00050,054,00092,512,256
8Jul 28, 2023 23:2017,198181,487,455107,347,00049,158,00092,528,640
9Jul 28, 2023 23:2017,206181,254,790108,707,00047,870,00092,450,816
10Jul 28, 2023 23:2017,208187,224,067115,698,00040,893,00092,491,776
11Jul 28, 2023 23:2017,223181,660,857110,809,00045,921,00092,569,600
12Jul 28, 2023 23:2017,361180,826,765114,990,00042,996,00091,983,872