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 listMay 10, 2024 00:45Joad NacerJoad NacerScore: 3,782Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1May 10, 2024 00:453,54961,455,20921,196,00011,102,00092,905,472
2May 10, 2024 00:453,62057,410,28720,965,00011,980,00092,950,528
3May 10, 2024 00:453,62260,298,81521,972,00010,986,00093,110,272
4May 10, 2024 00:453,62363,153,79320,983,00011,990,00092,889,088
5May 10, 2024 00:453,62565,216,16520,995,00011,997,00092,852,224
6May 10, 2024 00:453,63159,744,25521,026,00012,015,00092,925,952
7May 10, 2024 00:453,78293,182,37034,412,382094,490,624
8May 10, 2024 00:453,788105,069,55334,473,879094,490,624
9May 10, 2024 00:453,803107,021,04734,604,426094,490,624
10May 10, 2024 00:455,05872,796,42223,014,00023,014,00093,114,368
11May 10, 2024 00:456,29186,520,26624,103,00033,142,00093,294,592
12May 10, 2024 00:457,32194,644,43425,235,00041,386,00093,241,344