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 12, 2024 18:18Yuriy LyfenkoYuriy LyfenkoScore: 3,052Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Dec 12, 2024 18:183,039653,341,34517,780,0009,877,00092,893,184
2Dec 12, 2024 18:183,041655,802,98219,474,0008,199,00093,163,520
3Dec 12, 2024 18:183,049653,761,45118,828,0008,918,00093,143,040
4Dec 12, 2024 18:183,050654,434,04419,826,0007,930,00093,130,752
5Dec 12, 2024 18:183,052653,926,48519,840,0007,936,00093,093,888
6Dec 12, 2024 18:183,057655,854,75418,877,0008,941,00093,085,696
7Dec 12, 2024 18:183,060657,343,14516,908,00010,940,00093,138,944
8Dec 12, 2024 18:183,061656,385,95916,913,00010,943,00093,159,424
9Dec 12, 2024 18:183,067648,493,88417,941,0009,967,00093,089,792