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 24, 2024 18:23AnSaAnSaScore: 4,389Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 24, 2024 18:233,60957,279,41018,909,00013,933,00094,625,792
2Jun 24, 2024 18:233,61760,195,39219,949,00012,967,00094,699,520
3Jun 24, 2024 18:233,64360,984,52819,088,00014,065,00094,769,152
4Jun 24, 2024 18:233,85657,721,88320,053,00015,039,00094,916,608
5Jun 24, 2024 18:234,35894,548,47839,653,760096,702,464
6Jun 24, 2024 18:234,36698,658,13239,728,583094,613,504
7Jun 24, 2024 18:234,389111,082,67039,943,852096,714,752
8Jun 24, 2024 18:237,05390,610,93223,066,00041,118,00095,010,816
9Jun 24, 2024 18:237,14991,266,39024,021,00041,036,00095,019,008
10Jun 24, 2024 18:237,85597,406,21430,204,00041,278,00094,994,432
11Jun 24, 2024 18:238,695109,972,46529,046,00050,080,00095,166,464
12Jun 24, 2024 18:238,754109,438,08228,235,00051,428,00094,928,896