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:59Yuriy LyfenkoYuriy LyfenkoScore: 3,596Success
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:593,401653,123,08923,727,0007,221,00092,921,856
2Jul 26, 2024 21:593,402656,590,01819,974,00010,985,00093,196,288
3Jul 26, 2024 21:593,407656,060,00915,000,00016,000,00093,114,368
4Jul 26, 2024 21:593,408653,990,93519,009,00012,006,00093,188,096
5Jul 26, 2024 21:593,409654,541,53218,011,00013,008,00093,114,368
6Jul 26, 2024 21:593,413649,780,08426,050,0005,009,00093,216,768
7Jul 26, 2024 21:593,596703,545,04332,723,106094,740,480
8Jul 26, 2024 21:593,602705,735,02432,778,599094,609,408
9Jul 26, 2024 21:593,614684,995,11632,887,913094,605,312
10Jul 26, 2024 21:595,966674,371,89428,684,00025,610,00093,118,464
11Jul 26, 2024 21:596,460681,228,35625,907,00032,882,00093,093,888
12Jul 26, 2024 21:596,634687,909,19837,858,00022,510,00093,085,696