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 17:55AnSaAnSaScore: 6,543Success
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 17:553,81263,624,19321,804,00012,884,00091,918,336
2Jun 23, 2024 17:553,81564,672,38722,813,00011,902,00092,160,000
3Jun 23, 2024 17:553,81861,626,74723,825,00010,919,00091,897,856
4Jun 23, 2024 17:553,84862,699,44424,009,00011,004,00091,914,240
5Jun 23, 2024 17:554,52163,456,10225,088,00016,056,00092,143,616
6Jun 23, 2024 17:555,54281,140,13523,199,00027,233,00092,114,944
7Jun 23, 2024 17:556,543117,625,96859,544,412092,512,256
8Jun 23, 2024 17:556,548116,170,11459,587,195092,524,544
9Jun 23, 2024 17:556,563119,619,88259,722,383092,655,616
10Jun 23, 2024 17:556,75789,975,33023,185,00038,306,00092,184,576
11Jun 23, 2024 17:558,365103,301,20328,046,00048,080,00092,454,912
12Jun 23, 2024 17:558,716106,615,87129,115,00050,199,00092,491,776