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 6, 2021 18:59Yuriy LyfenkoYuriy LyfenkoScore: 9,563Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 6, 2021 18:594,749615,560,79743,217,842094,658,560
2Jun 6, 2021 18:594,750605,135,25743,229,232094,650,368
3Jun 6, 2021 18:594,809600,841,34243,764,217094,658,560
4Jun 6, 2021 18:599,522615,495,66268,511,00018,135,00094,683,136
5Jun 6, 2021 18:599,544616,431,91069,882,00016,971,00094,547,968
6Jun 6, 2021 18:599,549610,046,23470,727,00016,166,00094,547,968
7Jun 6, 2021 18:599,563612,257,66770,830,00016,189,00094,552,064
8Jun 6, 2021 18:599,603609,378,68071,316,00016,071,00094,547,968
9Jun 6, 2021 18:599,646610,544,33967,603,00020,180,00094,547,968
10Jun 6, 2021 18:599,803609,078,45868,161,00021,049,00093,241,344
11Jun 6, 2021 18:599,899614,306,90474,901,00015,182,00092,983,296
12Jun 6, 2021 18:599,940614,684,31068,095,00022,359,00093,241,344