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 13:40Ilya AniskovetsIlya AniskovetsScore: 9,891Success
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 13:409,661144,017,52287,910,804094,756,864
2Oct 31, 2021 13:409,670155,537,95787,997,971094,711,808
3Oct 31, 2021 13:409,687157,063,04488,148,443094,789,632
4Oct 31, 2021 13:409,872118,213,09142,920,00046,913,00094,801,920
5Oct 31, 2021 13:409,875116,290,44938,941,00050,923,00094,576,640
6Oct 31, 2021 13:409,887114,190,80037,990,00051,986,00094,547,968
7Oct 31, 2021 13:409,891109,710,41741,003,00049,004,00094,629,888
8Oct 31, 2021 13:409,914115,710,33537,090,00053,130,00094,736,384
9Oct 31, 2021 13:409,924120,783,87538,132,00052,180,00094,785,536
10Oct 31, 2021 13:4010,046111,401,50950,231,00041,189,00093,212,672
11Oct 31, 2021 13:4010,094119,163,60143,932,00047,926,00092,987,392
12Oct 31, 2021 13:4010,413117,266,80240,896,00053,863,00093,245,440