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 14:30AnSaAnSaScore: 5,187Success
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 14:304,58471,150,27221,850,00019,864,00091,906,048
2Jun 23, 2024 14:304,59273,076,08332,830,0008,953,00091,938,816
3Jun 23, 2024 14:304,94268,335,66731,982,00012,992,00091,906,048
4Jun 23, 2024 14:305,03875,195,04725,915,00019,934,00092,151,808
5Jun 23, 2024 14:305,160110,049,84446,953,618092,532,736
6Jun 23, 2024 14:305,160115,119,19446,960,249092,524,544
7Jun 23, 2024 14:305,187107,403,43447,202,654092,524,544
8Jun 23, 2024 14:305,52576,088,48734,192,00016,090,00092,172,288
9Jun 23, 2024 14:308,158109,560,27640,128,00034,108,00092,315,648
10Jun 23, 2024 14:309,239108,267,29535,031,00049,044,00092,385,280
11Jun 23, 2024 14:309,270115,843,39239,165,00045,191,00092,332,032
12Jun 23, 2024 14:309,640115,593,75138,878,00048,847,00092,225,536