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 22:22Yuriy LyfenkoYuriy LyfenkoScore: 7,014Success
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 22:223,511656,818,54821,967,0009,985,00093,184,000
2Jul 26, 2024 22:223,525658,610,88924,833,0007,242,00092,889,088
3Jul 26, 2024 22:223,535650,240,05723,123,0009,048,00093,110,272
4Jul 26, 2024 22:223,536653,148,76224,137,0008,045,00093,134,848
5Jul 26, 2024 22:224,199660,027,60323,127,00015,082,00093,204,480
6Jul 26, 2024 22:224,480670,973,57823,864,00016,903,00092,934,144
7Jul 26, 2024 22:227,014682,838,80529,921,00033,910,00093,335,552
8Jul 26, 2024 22:227,199691,667,39939,307,00026,205,00093,327,360
9Jul 26, 2024 22:227,207689,662,78636,889,00028,691,00093,327,360
10Jul 26, 2024 22:228,911747,003,04581,088,198094,654,464
11Jul 26, 2024 22:228,913744,877,72481,105,699094,646,272
12Jul 26, 2024 22:228,914743,049,18981,115,591094,744,576