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:32Joad NacerJoad NacerScore: 3,959Success
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:323,82259,739,64522,854,00011,924,00092,897,280
2Apr 22, 2024 01:323,82466,375,40723,859,00010,935,00092,880,896
3Apr 22, 2024 01:323,82659,286,95423,874,00010,942,00092,934,144
4Apr 22, 2024 01:323,83261,231,38422,916,00011,956,00092,872,704
5Apr 22, 2024 01:323,83860,658,50222,951,00011,974,00092,921,856
6Apr 22, 2024 01:323,83960,029,87022,957,00011,977,00092,889,088
7Apr 22, 2024 01:323,95991,915,11136,022,530094,482,432
8Apr 22, 2024 01:323,96398,161,04936,063,806094,482,432
9Apr 22, 2024 01:323,986103,219,64636,275,977094,494,720
10Apr 22, 2024 01:324,30967,588,97924,129,00015,080,00093,118,464
11Apr 22, 2024 01:324,42166,116,29424,137,00016,091,00093,175,808
12Apr 22, 2024 01:327,844101,064,85028,150,00043,231,00093,274,112