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:41Mikhail ShirokovMikhail ShirokovScore: 9,630Success
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:419,614118,946,87178,439,0009,050,000103,284,736
2Jan 11, 2025 11:419,618116,005,68879,476,0008,048,000103,346,176
3Jan 11, 2025 11:419,619119,388,73480,492,0007,043,000103,194,624
4Jan 11, 2025 11:419,625113,850,30477,638,0009,953,000103,030,784
5Jan 11, 2025 11:419,630116,617,39876,676,00010,953,000103,260,160
6Jan 11, 2025 11:419,630119,849,82478,670,0008,962,000103,182,336
7Jan 11, 2025 11:419,631120,180,80375,688,00011,950,000103,190,528
8Jan 11, 2025 11:419,640113,145,70077,757,0009,968,000103,215,104
9Jan 11, 2025 11:419,647117,226,48077,815,0009,976,000103,038,976