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 12, 2024 00:58Joad NacerJoad NacerScore: 3,761Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 12, 2024 00:583,52957,244,46921,076,00011,040,00092,958,720
2May 12, 2024 00:583,53159,035,12121,085,00011,044,00092,934,144
3May 12, 2024 00:583,53461,492,55521,102,00011,053,00092,942,336
4May 12, 2024 00:583,55854,827,17121,250,00011,131,00092,889,088
5May 12, 2024 00:583,56157,923,77121,266,00011,139,00092,946,432
6May 12, 2024 00:583,758103,635,97734,193,885094,486,528
7May 12, 2024 00:583,76191,366,86234,220,843094,486,528
8May 12, 2024 00:583,78990,995,27234,480,760094,482,432
9May 12, 2024 00:584,29061,544,14723,025,00016,017,00093,147,136
10May 12, 2024 00:587,34891,458,55325,948,00040,918,00093,331,456
11May 12, 2024 00:587,40697,136,58526,152,00041,240,00093,138,944
12May 12, 2024 00:587,60691,766,52326,082,00043,135,00093,257,728