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 10:34Mikhail ShirokovMikhail ShirokovScore: 10,871Success
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 10:3410,859127,103,72784,846,00013,974,000103,108,608
2Jan 11, 2025 10:3510,866126,007,87089,893,0008,989,000103,260,160
3Jan 11, 2025 10:3510,870121,878,89589,927,0008,992,000103,292,928
4Jan 11, 2025 10:3410,871131,693,49291,932,0006,994,000103,264,256
5Jan 11, 2025 10:3510,885121,992,34089,050,00010,005,000103,215,104
6Jan 11, 2025 10:3410,904120,139,48089,201,00010,022,000103,329,792