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 listSep 8, 2024 15:51Yuriy LyfenkoYuriy LyfenkoScore: 3,372Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Sep 8, 2024 15:513,35860,198,22117,314,00013,240,00092,925,952
2Sep 8, 2024 15:483,36355,563,26916,781,00013,820,00093,020,160
3Sep 8, 2024 15:483,36854,082,22320,764,0009,887,00093,147,136
4Sep 8, 2024 15:513,37255,608,11316,826,00013,857,00093,032,448
5Sep 8, 2024 15:483,39255,960,69427,877,0002,986,00093,061,120
6Sep 8, 2024 15:513,39655,659,32526,918,0003,987,00093,138,944