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:18Yuriy LyfenkoYuriy LyfenkoScore: 3,458Success
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:183,318656,703,36323,152,0007,046,00093,151,232
2Jul 26, 2024 22:183,319655,026,43926,039,0004,166,00092,925,952
3Jul 26, 2024 22:183,321661,484,71122,929,0007,295,00092,856,320
4Jul 26, 2024 22:183,326656,504,45523,206,0007,062,00093,208,576
5Jul 26, 2024 22:183,330652,374,13823,233,0007,071,00092,909,568
6Jul 26, 2024 22:183,345654,439,79724,349,0006,087,00092,880,896
7Jul 26, 2024 22:183,458699,773,02031,471,636094,642,176
8Jul 26, 2024 22:183,472694,558,46031,598,796094,777,344
9Jul 26, 2024 22:183,482694,180,16631,685,093094,609,408
10Jul 26, 2024 22:185,562681,076,39530,366,00020,244,00093,134,848
11Jul 26, 2024 22:186,299681,061,53625,590,00031,732,00093,097,984
12Jul 26, 2024 22:186,821681,683,50829,507,00032,560,00093,335,552