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 listApr 22, 2024 01:21Joad NacerJoad NacerScore: 3,911Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 01:213,82560,858,29223,868,00010,939,00092,884,992
2Apr 22, 2024 01:213,84161,144,46524,969,0009,987,00092,905,472
3Apr 22, 2024 01:213,86464,493,61423,107,00012,055,00093,167,616
4Apr 22, 2024 01:213,86864,189,67523,131,00012,068,00092,897,280
5Apr 22, 2024 01:213,87363,817,77223,159,00012,083,00092,917,760
6Apr 22, 2024 01:213,89961,488,38824,332,00011,152,00092,942,336
7Apr 22, 2024 01:213,91166,296,58824,403,00011,184,00092,893,184
8Apr 22, 2024 01:214,061107,217,86136,959,412094,478,336
9Apr 22, 2024 01:214,075101,792,51837,085,060094,486,528
10Apr 22, 2024 01:214,09393,525,98237,250,267094,490,624
11Apr 22, 2024 01:214,71371,150,11624,933,00017,952,00093,179,904
12Apr 22, 2024 01:215,38176,310,23125,981,00022,983,00093,196,288