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 listJun 23, 2024 16:06AnSaAnSaScore: 5,349Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 23, 2024 16:064,72271,260,21029,982,00012,992,00091,889,664
2Jun 23, 2024 16:064,73375,288,86430,048,00013,020,00091,971,584
3Jun 23, 2024 16:064,78872,988,71728,719,00014,854,00091,918,336
4Jun 23, 2024 16:064,87769,877,11629,252,00015,130,00092,160,000
5Jun 23, 2024 16:065,10974,447,24030,320,00016,170,00091,893,760
6Jun 23, 2024 16:065,321105,755,46148,417,917092,524,544
7Jun 23, 2024 16:065,349129,623,37448,675,168092,659,712
8Jun 23, 2024 16:065,360132,731,76348,778,596092,655,616
9Jun 23, 2024 16:066,37386,977,45529,998,00027,999,00092,114,944
10Jun 23, 2024 16:068,876105,957,40536,897,00043,878,00092,241,920
11Jun 23, 2024 16:069,539120,088,96540,910,00045,899,00092,188,672
12Jun 23, 2024 16:069,791112,231,79739,043,00050,056,00092,471,296