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 listApr 22, 2024 02:25Yuriy LyfenkoYuriy LyfenkoScore: 3,730Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Apr 22, 2024 02:253,382558,946,62115,883,00014,890,00092,897,280
2Apr 22, 2024 02:253,388557,056,69414,920,00015,915,00093,040,640
3Apr 22, 2024 02:253,389557,070,57622,880,0007,958,00092,868,608
4Apr 22, 2024 02:253,390558,190,98920,900,0009,952,00092,921,856
5Apr 22, 2024 02:253,527553,304,20421,063,00011,033,00092,966,912
6Apr 22, 2024 02:253,542554,374,77223,169,0009,066,00092,966,912
7Apr 22, 2024 02:253,730595,134,66933,945,024094,605,312
8Apr 22, 2024 02:253,748586,577,24234,103,935094,605,312
9Apr 22, 2024 02:253,751596,404,11334,130,297094,601,216
10Apr 22, 2024 02:256,049577,614,27824,019,00031,025,00093,118,464
11Apr 22, 2024 02:257,066585,930,42931,146,00033,156,00093,061,120
12Apr 22, 2024 02:257,161592,517,53329,073,00036,091,00093,319,168