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 listOct 31, 2021 14:06Ilya AniskovetsIlya AniskovetsScore: 10,179Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Oct 31, 2021 14:0610,112116,740,33343,008,00049,009,00094,580,736
2Oct 31, 2021 14:0610,118115,481,07647,039,00045,037,00094,728,192
3Oct 31, 2021 14:0610,121115,405,46443,045,00049,052,00094,674,944
4Oct 31, 2021 14:0610,132116,070,28443,094,00049,107,00094,556,160
5Oct 31, 2021 14:0610,132121,090,43448,106,00044,097,00092,889,088
6Oct 31, 2021 14:0610,156119,983,59242,191,00050,228,00094,683,136
7Oct 31, 2021 14:0610,179124,563,93743,824,00048,804,00094,711,808
8Oct 31, 2021 14:0610,200114,671,61440,920,00051,898,00094,679,040
9Oct 31, 2021 14:0610,310116,833,46843,917,00049,906,00093,089,792
10Oct 31, 2021 14:0610,494154,709,13295,499,034094,744,576
11Oct 31, 2021 14:0610,513153,479,33895,667,925094,756,864
12Oct 31, 2021 14:0610,533158,348,43095,847,203094,674,944