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 24, 2024 18:38AnSaAnSaScore: 4,357Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 24, 2024 18:383,61758,675,34320,944,00011,968,00097,198,080
2Jun 24, 2024 18:383,64756,759,22418,104,00015,086,00097,218,560
3Jun 24, 2024 18:383,66057,577,72719,178,00014,131,00097,226,752
4Jun 24, 2024 18:383,78258,848,29220,246,00014,172,00097,214,464
5Jun 24, 2024 18:384,34999,009,38639,578,703098,799,616
6Jun 24, 2024 18:384,352103,697,54339,600,402098,799,616
7Jun 24, 2024 18:384,357104,628,75739,652,835098,799,616
8Jun 24, 2024 18:385,13779,459,93921,883,00024,867,00097,431,552
9Jun 24, 2024 18:385,84076,560,04820,056,00033,092,00097,394,688
10Jun 24, 2024 18:388,210103,868,41429,279,00045,433,00097,509,376
11Jun 24, 2024 18:388,623106,520,88022,133,00056,340,00097,792,000
12Jun 24, 2024 18:388,664109,281,96727,943,00050,896,00097,538,048