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:00Ilya AniskovetsIlya AniskovetsScore: 9,656Success
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:009,564144,621,60887,029,072094,670,848
2Oct 31, 2021 14:009,578159,744,95087,156,822094,724,096
3Oct 31, 2021 14:009,589128,535,35387,264,285094,699,520
4Oct 31, 2021 14:009,633116,551,06944,826,00042,834,00094,658,560
5Oct 31, 2021 14:009,644110,635,34643,881,00043,881,00094,588,928
6Oct 31, 2021 14:009,648116,009,43036,913,00050,880,00094,617,600
7Oct 31, 2021 14:009,656110,348,69739,940,00047,928,00094,584,832
8Oct 31, 2021 14:009,663112,561,58941,969,00045,966,00094,748,672
9Oct 31, 2021 14:009,685110,876,59637,055,00051,076,00094,650,368
10Oct 31, 2021 14:009,687111,261,19640,069,00048,083,00094,543,872
11Oct 31, 2021 14:009,688108,819,85042,076,00046,083,00094,789,632
12Oct 31, 2021 14:0010,275120,215,01138,205,00055,296,00093,216,768