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 26, 2024 22:08Yuriy LyfenkoYuriy LyfenkoScore: 3,681Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jul 26, 2024 22:083,480655,017,12723,494,0008,172,00093,102,080
2Jul 26, 2024 22:083,484658,951,99420,806,00010,898,00093,110,272
3Jul 26, 2024 22:083,486659,664,77320,818,00010,905,00092,934,144
4Jul 26, 2024 22:083,487657,797,02021,818,0009,917,00093,188,096
5Jul 26, 2024 22:083,495655,931,48724,845,0006,956,00093,130,752
6Jul 26, 2024 22:083,674696,207,12233,431,364094,609,408
7Jul 26, 2024 22:083,681685,852,30233,500,092094,609,408
8Jul 26, 2024 22:083,691690,835,54933,592,085094,613,504
9Jul 26, 2024 22:084,154662,324,61725,542,00012,260,00092,946,432
10Jul 26, 2024 22:084,848673,383,94026,070,00018,048,00093,175,808
11Jul 26, 2024 22:084,857665,581,00026,116,00018,080,00093,175,808
12Jul 26, 2024 22:087,245686,212,02635,960,00029,967,00093,323,264