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 listJun 23, 2024 18:07AnSaAnSaScore: 6,673Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 23, 2024 18:073,85766,992,47924,069,00011,031,00091,852,800
2Jun 23, 2024 18:073,87462,800,74526,185,0009,064,00091,914,240
3Jun 23, 2024 18:073,88462,658,62823,229,00012,119,00091,938,816
4Jun 23, 2024 18:074,48069,562,66123,863,00016,903,00092,164,096
5Jun 23, 2024 18:075,36581,166,80921,919,00026,901,00092,143,616
6Jun 23, 2024 18:076,666125,903,40060,660,069092,516,352
7Jun 23, 2024 18:076,673113,704,44960,721,245092,782,592
8Jun 23, 2024 18:076,673127,788,48360,721,746092,528,640
9Jun 23, 2024 18:076,68182,238,56727,908,00032,892,00092,332,032
10Jun 23, 2024 18:078,434108,671,48831,896,00044,853,00092,340,224
11Jun 23, 2024 18:078,764107,604,53727,914,00051,841,00092,274,688
12Jun 23, 2024 18:078,936115,420,19628,111,00053,211,00092,487,680