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 listJun 23, 2024 15:58AnSaAnSaScore: 5,528Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 23, 2024 15:584,80174,019,43727,801,00015,886,00091,889,664
2Jun 23, 2024 15:584,80368,496,45430,793,00012,913,00091,893,760
3Jun 23, 2024 15:584,80769,354,78232,810,00010,936,00091,979,776
4Jun 23, 2024 15:585,37575,236,07030,943,00017,967,00092,164,096
5Jun 23, 2024 15:585,481103,899,79149,881,270092,520,448
6Jun 23, 2024 15:585,493124,481,13949,989,489092,528,640
7Jun 23, 2024 15:585,528110,926,23050,302,206092,512,256
8Jun 23, 2024 15:585,74074,698,04231,138,00021,093,00092,155,904
9Jun 23, 2024 15:587,13591,430,89331,965,00032,964,00092,340,224
10Jun 23, 2024 15:589,404114,983,23335,238,00050,341,00092,164,096
11Jun 23, 2024 15:589,826117,246,95436,169,00053,249,00092,344,320
12Jun 23, 2024 15:589,879124,253,25443,952,00045,949,00092,246,016