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 27, 2024 14:47Joad NacerJoad NacerScore: 3,252Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 14:473,17555,658,15017,931,00010,958,00093,200,384
2Jul 27, 2024 14:473,22351,176,81419,217,00010,114,00093,134,848
3Jul 27, 2024 14:473,22949,815,25220,266,0009,120,00093,089,792
4Jul 27, 2024 14:473,23752,744,99820,315,0009,141,00093,016,064
5Jul 27, 2024 14:473,23950,760,07020,329,0009,148,00093,040,640
6Jul 27, 2024 14:473,24861,429,03720,383,0009,172,00093,007,872
7Jul 27, 2024 14:473,25254,122,21419,389,00010,204,00092,930,048
8Jul 27, 2024 14:473,36486,886,08930,615,498094,490,624
9Jul 27, 2024 14:473,37092,894,40830,665,949094,502,912
10Jul 27, 2024 14:473,37691,656,28130,720,466094,498,816
11Jul 27, 2024 14:475,53579,228,09721,155,00029,215,00093,188,096
12Jul 27, 2024 14:476,64283,892,18123,169,00037,271,00093,306,880