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:01Yuriy LyfenkoYuriy LyfenkoScore: 3,685Success
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:013,667564,758,38424,271,0009,101,00092,913,664
2Apr 22, 2024 02:013,670598,273,11233,393,228094,609,408
3Apr 22, 2024 02:013,672559,834,64624,304,0009,114,00093,024,256
4Apr 22, 2024 02:013,672565,985,35723,292,00010,127,00092,884,992
5Apr 22, 2024 02:013,674558,080,80724,315,0009,118,00092,884,992
6Apr 22, 2024 02:013,680563,361,41624,352,0009,132,00092,880,896
7Apr 22, 2024 02:013,685568,011,79725,403,0008,128,00092,868,608
8Apr 22, 2024 02:013,687558,330,16924,400,0009,150,00092,954,624
9Apr 22, 2024 02:013,688593,443,72933,557,262094,617,600
10Apr 22, 2024 02:013,693598,887,97533,604,699094,633,984
11Apr 22, 2024 02:014,349570,596,23326,034,00013,538,00092,917,760
12Apr 22, 2024 02:014,464572,175,59927,795,00012,828,00092,938,240