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 listJul 26, 2024 22:21Yuriy LyfenkoYuriy LyfenkoScore: 3,602Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 22:213,503658,357,42523,649,0008,226,00093,089,792
2Jul 26, 2024 22:213,509664,068,50823,951,0007,983,00092,917,760
3Jul 26, 2024 22:213,519658,385,14022,014,00010,006,00092,884,992
4Jul 26, 2024 22:213,521651,026,89022,030,00010,013,00093,184,000
5Jul 26, 2024 22:213,524652,333,98922,046,00010,021,00093,073,408
6Jul 26, 2024 22:213,600691,568,73732,760,151094,638,080
7Jul 26, 2024 22:213,602703,262,82732,779,065094,609,408
8Jul 26, 2024 22:213,616701,267,59432,906,691094,642,176
9Jul 26, 2024 22:214,477662,467,97725,835,00014,904,00092,930,048
10Jul 26, 2024 22:216,516682,257,73335,177,00024,122,00093,097,984
11Jul 26, 2024 22:217,175687,901,88536,161,00029,130,00093,237,248
12Jul 26, 2024 22:217,184692,362,92925,537,00039,838,00093,323,264