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 listDec 13, 2024 00:08Joad NacerJoad NacerScore: 3,166Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 13, 2024 00:083,13051,020,85423,399,0005,086,00093,032,448
2Dec 13, 2024 00:083,15349,896,96822,758,0005,937,00093,134,848
3Dec 13, 2024 00:083,15456,807,52318,803,0009,896,00093,126,656
4Dec 13, 2024 00:083,16452,454,81921,845,0006,950,00092,884,992
5Dec 13, 2024 00:083,16655,508,00422,847,0005,960,00093,130,752
6Dec 13, 2024 00:083,16658,174,30921,856,0006,954,00092,905,472
7Dec 13, 2024 00:083,16754,728,35522,854,0005,962,00093,016,064
8Dec 13, 2024 00:083,17051,845,09622,876,0005,967,00093,028,352
9Dec 13, 2024 00:083,17254,526,63722,893,0005,972,00093,011,968