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 02:23Yuriy LyfenkoYuriy LyfenkoScore: 3,667Success
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 02:233,390655,153,06519,903,00010,946,00092,893,184
2Apr 22, 2024 02:233,395655,322,44819,934,00010,964,00092,930,048
3Apr 22, 2024 02:233,401657,616,51613,978,00016,973,00092,934,144
4Apr 22, 2024 02:233,405654,385,82027,991,0002,999,00092,962,816
5Apr 22, 2024 02:233,407660,488,49915,003,00016,003,00092,876,800
6Apr 22, 2024 02:233,421658,309,27428,115,0003,012,00092,983,296
7Apr 22, 2024 02:233,667690,261,54633,372,879094,605,312
8Apr 22, 2024 02:233,673703,349,93433,424,218094,605,312
9Apr 22, 2024 02:233,697693,385,91733,643,367094,609,408
10Apr 22, 2024 02:234,040662,769,16223,107,00013,654,00092,876,800
11Apr 22, 2024 02:234,059658,598,94318,995,00017,940,00092,868,608
12Apr 22, 2024 02:234,167666,517,04328,694,0009,223,00092,938,240