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:38Ilya AniskovetsIlya AniskovetsScore: 9,885Success
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:389,678152,365,09788,068,192094,756,864
2Oct 31, 2021 13:389,682158,364,10488,104,972094,670,848
3Oct 31, 2021 13:389,708151,360,37788,344,580094,674,944
4Oct 31, 2021 13:389,866116,204,61845,888,00043,893,00094,625,792
5Oct 31, 2021 13:389,870114,113,66839,918,00049,898,00094,625,792
6Oct 31, 2021 13:389,873115,593,44138,932,00050,911,00094,785,536
7Oct 31, 2021 13:389,885116,277,63738,979,00050,972,00094,752,768
8Oct 31, 2021 13:389,908115,114,79146,081,00044,078,00094,584,832
9Oct 31, 2021 13:389,910115,097,13336,072,00054,108,00094,584,832
10Oct 31, 2021 13:389,925115,172,56633,117,00057,202,00092,979,200
11Oct 31, 2021 13:389,936120,688,61039,181,00051,236,00094,547,968
12Oct 31, 2021 13:3810,445120,505,93640,022,00055,031,00093,196,288