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:54Joad NacerJoad NacerScore: 3,773Success
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:543,55354,660,38121,216,00011,113,00092,913,664
2May 9, 2024 23:543,56252,997,68921,272,00011,142,00092,897,280
3May 9, 2024 23:543,56257,221,24923,300,0009,117,00093,134,848
4May 9, 2024 23:543,61261,421,68920,918,00011,953,00092,913,664
5May 9, 2024 23:543,63558,594,88521,049,00012,028,00092,999,680
6May 9, 2024 23:543,768101,516,75334,292,159094,490,624
7May 9, 2024 23:543,773102,514,42134,332,605094,486,528
8May 9, 2024 23:543,78989,749,12834,479,603094,486,528
9May 9, 2024 23:544,16471,164,49622,935,00014,957,00093,155,328
10May 9, 2024 23:546,52984,407,88024,169,00035,247,00093,237,248
11May 9, 2024 23:547,19589,689,71926,190,00039,286,00093,077,504
12May 9, 2024 23:547,543100,014,41826,244,00042,395,00093,245,440