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 listJul 27, 2024 19:59Joad NacerJoad NacerScore: 3,414Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 27, 2024 19:593,19554,454,09718,048,00011,029,00092,934,144
2Jul 27, 2024 19:593,25056,141,36320,395,0009,178,00093,155,328
3Jul 27, 2024 19:593,27255,598,09918,859,00010,918,00093,192,192
4Jul 27, 2024 19:593,27757,546,52619,882,0009,941,00093,069,312
5Jul 27, 2024 19:593,29557,387,85218,990,00010,994,00093,028,352
6Jul 27, 2024 19:593,40390,053,62230,971,706094,486,528
7Jul 27, 2024 19:593,41485,434,08531,068,878094,494,720
8Jul 27, 2024 19:593,42491,258,70331,159,364094,633,984
9Jul 27, 2024 19:593,60954,375,24719,906,00012,939,00093,175,808
10Jul 27, 2024 19:595,11570,877,43422,260,00024,284,00093,147,136
11Jul 27, 2024 19:596,03078,788,86822,946,00031,926,00093,212,672
12Jul 27, 2024 19:597,15789,884,96423,047,00042,086,00093,249,536