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 18:11AnSaAnSaScore: 6,414Success
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 18:113,70859,699,02121,834,00011,909,00091,918,336
2Jun 23, 2024 18:113,71464,169,52220,877,00012,923,00091,889,664
3Jun 23, 2024 18:113,72861,680,00221,953,00011,974,00091,901,952
4Jun 23, 2024 18:114,59765,029,62519,921,00021,913,00092,143,616
5Jun 23, 2024 18:114,62266,590,61121,032,00021,032,00092,168,192
6Jun 23, 2024 18:115,69276,654,77521,915,00029,885,00092,090,368
7Jun 23, 2024 18:116,414112,855,24858,366,647092,528,640
8Jun 23, 2024 18:116,425114,349,28758,466,997092,524,544
9Jun 23, 2024 18:116,454133,890,55258,727,072092,516,352
10Jun 23, 2024 18:118,394110,609,62031,158,00045,229,00092,160,000
11Jun 23, 2024 18:118,551103,143,23431,923,00045,889,00092,254,208
12Jun 23, 2024 18:118,655101,531,02128,911,00049,847,00092,295,168