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 19:02Yuriy LyfenkoYuriy LyfenkoScore: 9,608Success
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 19:024,639598,977,85942,215,529094,646,272
2Jun 6, 2021 19:024,643592,432,25342,251,601094,654,464
3Jun 6, 2021 19:024,670591,653,86542,492,535094,662,656
4Jun 6, 2021 19:029,568608,156,18371,883,00015,186,00094,547,968
5Jun 6, 2021 19:029,593617,402,11870,239,00017,058,00094,547,968
6Jun 6, 2021 19:029,607613,812,25872,351,00015,073,00094,547,968
7Jun 6, 2021 19:029,608613,766,79567,331,00020,098,00094,687,232
8Jun 6, 2021 19:029,614616,255,91770,395,00017,096,00094,674,944
9Jun 6, 2021 19:029,676610,521,00267,812,00020,242,00094,547,968
10Jun 6, 2021 19:029,680607,357,06272,075,00016,016,00092,979,200
11Jun 6, 2021 19:029,812613,441,76368,993,00020,292,00093,241,344
12Jun 6, 2021 19:0210,004614,053,64770,809,00020,231,00093,233,152