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 23, 2024 22:21Joad NacerJoad NacerScore: 4,021Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 23, 2024 22:213,66861,048,94422,253,00011,126,00092,848,128
2Apr 23, 2024 22:213,67056,961,33125,299,0008,095,00092,917,760
3Apr 23, 2024 22:213,67158,460,66324,296,0009,111,00092,905,472
4Apr 23, 2024 22:213,68164,853,52120,302,00013,196,00092,844,032
5Apr 23, 2024 22:213,68657,728,20522,365,00011,182,00092,860,416
6Apr 23, 2024 22:214,01592,498,87636,536,930094,482,432
7Apr 23, 2024 22:214,021120,450,34236,592,798094,605,312
8Apr 23, 2024 22:214,039108,791,59536,753,428094,515,200
9Apr 23, 2024 22:214,21164,523,20224,201,00014,117,00093,184,000
10Apr 23, 2024 22:216,38086,918,37226,024,00032,030,00093,147,136
11Apr 23, 2024 22:217,02793,979,71828,977,00034,972,00093,265,920
12Apr 23, 2024 22:217,781100,649,66932,909,00037,895,00093,417,472