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 16:01AnSaAnSaScore: 5,305Success
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 16:014,84772,543,84431,074,00013,031,00091,889,664
2Jun 23, 2024 16:014,85267,361,32331,109,00013,045,00091,938,816
3Jun 23, 2024 16:014,90771,359,33931,757,00012,901,00092,020,736
4Jun 23, 2024 16:014,92176,215,74431,843,00012,936,00091,848,704
5Jun 23, 2024 16:015,288110,802,44348,124,108092,524,544
6Jun 23, 2024 16:015,301116,795,26748,242,257092,663,808
7Jun 23, 2024 16:015,305125,588,72948,273,655092,524,544
8Jun 23, 2024 16:015,59274,262,71932,925,00017,959,00092,168,192
9Jun 23, 2024 16:015,66283,062,69030,307,00021,215,00092,168,192
10Jun 23, 2024 16:016,75588,457,97033,255,00028,216,00092,114,944
11Jun 23, 2024 16:019,489114,248,13236,147,00050,204,00092,217,344
12Jun 23, 2024 16:019,873114,492,34538,932,00050,911,00092,307,456