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:43Ilya AniskovetsIlya AniskovetsScore: 9,815Success
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:439,296146,264,62784,589,963094,674,944
2Oct 31, 2021 13:439,332127,897,81684,922,966094,760,960
3Oct 31, 2021 13:439,350152,929,07785,085,535094,789,632
4Oct 31, 2021 13:439,792116,115,02439,047,00050,060,00094,797,824
5Oct 31, 2021 13:439,796114,693,77443,069,00046,074,00094,785,536
6Oct 31, 2021 13:439,806116,924,56745,121,00044,118,00094,568,448
7Oct 31, 2021 13:439,815111,404,61036,129,00053,190,00094,765,056
8Oct 31, 2021 13:439,825117,505,86941,189,00048,222,00094,568,448
9Oct 31, 2021 13:439,836117,025,58744,752,00044,752,00094,629,888
10Oct 31, 2021 13:439,858114,065,24147,842,00041,862,00093,024,256
11Oct 31, 2021 13:4310,238120,320,84137,066,00056,100,00093,270,016
12Oct 31, 2021 13:4310,316118,457,55844,943,00048,937,00093,167,616