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:23Joad NacerJoad NacerScore: 3,984Success
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,78060,470,99825,295,0009,106,00092,876,800
2Apr 22, 2024 02:233,78863,794,84625,347,0009,124,00092,938,240
3Apr 22, 2024 02:233,80765,476,49022,766,00011,878,00092,946,432
4Apr 22, 2024 02:233,81362,104,66823,794,00010,905,00092,893,184
5Apr 22, 2024 02:233,83457,951,09423,927,00010,966,00093,040,640
6Apr 22, 2024 02:233,981109,218,34736,226,580094,494,720
7Apr 22, 2024 02:233,98495,794,59936,258,746094,482,432
8Apr 22, 2024 02:233,987101,713,84036,286,003094,490,624
9Apr 22, 2024 02:235,61775,797,55225,055,00026,057,00093,036,544
10Apr 22, 2024 02:236,90190,438,62427,911,00034,889,00093,290,496
11Apr 22, 2024 02:237,48793,446,14627,051,00041,078,00093,290,496
12Apr 22, 2024 02:237,70295,752,97329,036,00041,051,00093,302,784