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 listJan 11, 2025 11:31Mikhail ShirokovMikhail ShirokovScore: 9,797Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jan 11, 2025 11:319,758113,820,14779,822,0008,979,000103,108,608
2Jan 11, 2025 11:319,771113,705,99579,927,0008,991,000103,145,472
3Jan 11, 2025 11:319,776114,852,44878,966,0009,995,000103,084,032
4Jan 11, 2025 11:319,780109,234,54579,000,00010,000,000103,170,048
5Jan 11, 2025 11:319,797114,992,86081,141,0008,014,000103,149,568
6Jan 11, 2025 11:319,806120,765,62579,205,00010,026,000103,112,704
7Jan 11, 2025 11:319,815118,861,33079,277,00010,035,000103,198,720
8Jan 11, 2025 11:319,952115,184,54079,616,00010,947,000103,174,144
9Jan 11, 2025 11:319,995116,287,25880,959,0009,995,000103,174,144