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:48Yuriy LyfenkoYuriy LyfenkoScore: 3,597Success
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:483,399658,653,61114,965,00015,962,00093,200,384
2Jul 26, 2024 21:483,404654,579,14713,988,00016,985,00092,893,184
3Jul 26, 2024 21:483,407652,045,64119,001,00012,000,00093,220,864
4Jul 26, 2024 21:483,408658,356,08819,009,00012,006,00093,122,560
5Jul 26, 2024 21:483,410657,430,16430,031,0001,001,00093,188,096
6Jul 26, 2024 21:483,414653,289,17921,047,00010,022,00092,884,992
7Jul 26, 2024 21:483,597691,569,69732,731,891094,650,368
8Jul 26, 2024 21:483,604694,168,82332,793,755094,609,408
9Jul 26, 2024 21:483,610707,052,90632,846,736094,613,504
10Jul 26, 2024 21:484,939669,498,57716,978,00027,964,00093,073,408
11Jul 26, 2024 21:485,947676,689,03025,526,00028,589,00093,118,464
12Jul 26, 2024 21:486,566682,925,80332,861,00026,886,00093,253,632