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 listJul 26, 2024 21:31Yuriy LyfenkoYuriy LyfenkoScore: 3,665Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 21:313,437552,369,43922,939,0008,341,00093,208,576
2Jul 26, 2024 21:313,443554,516,86524,023,0007,311,00092,979,200
3Jul 26, 2024 21:313,447550,927,58923,276,0008,096,00092,930,048
4Jul 26, 2024 21:313,451557,152,81821,276,00010,131,00093,171,712
5Jul 26, 2024 21:313,463561,989,14022,367,0009,150,00092,827,648
6Jul 26, 2024 21:313,472557,750,86020,735,00010,861,00093,036,544
7Jul 26, 2024 21:313,665593,829,17333,350,794094,646,272
8Jul 26, 2024 21:313,681598,487,18633,500,659094,609,408
9Jul 26, 2024 21:313,689589,753,02833,568,507094,638,080
10Jul 26, 2024 21:315,522569,601,26231,153,00019,094,00093,143,040
11Jul 26, 2024 21:317,056587,795,25435,113,00029,093,00093,331,456
12Jul 26, 2024 21:317,198588,715,23930,706,00034,800,00093,323,264