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 15:46AnSaAnSaScore: 7,226Success
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 15:464,43767,816,97027,257,00013,123,00091,967,488
2Jun 23, 2024 15:464,47367,687,14526,805,00013,899,00091,881,472
3Jun 23, 2024 15:464,51665,603,37927,063,00014,032,00091,934,720
4Jun 23, 2024 15:465,14479,653,57628,885,00017,929,00092,151,808
5Jun 23, 2024 15:466,02186,387,47529,888,00024,907,00092,147,712
6Jun 23, 2024 15:466,02281,622,90730,885,00023,911,00092,110,848
7Jun 23, 2024 15:467,226127,683,51365,760,442092,520,448
8Jun 23, 2024 15:467,258120,890,76266,050,919092,524,544
9Jun 23, 2024 15:467,260120,640,64566,069,911092,512,256
10Jun 23, 2024 15:469,182114,502,31027,180,00056,373,00092,254,208
11Jun 23, 2024 15:469,305110,060,25142,336,00042,336,00092,266,496
12Jun 23, 2024 15:469,431113,557,22539,919,00045,907,00092,299,264