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 listJun 24, 2024 20:19Joad NacerJoad NacerScore: 3,623Success
Source Code

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

Challenge History

No challenges yet.

Run Statistics
#DateScoreWall TimeCPU UserCPU SystemMemoryError
1Jun 24, 2024 20:193,48456,966,55322,787,0008,916,00092,860,416
2Jun 24, 2024 20:193,50162,107,50820,909,00010,952,00092,893,184
3Jun 24, 2024 20:193,50361,549,80020,922,00010,959,00092,921,856
4Jun 24, 2024 20:193,53057,772,47421,083,00011,043,00092,889,088
5Jun 24, 2024 20:193,58789,284,43432,643,359094,482,432
6Jun 24, 2024 20:193,603111,203,32932,790,246094,490,624
7Jun 24, 2024 20:193,62399,977,14032,973,355094,609,408
8Jun 24, 2024 20:194,23764,037,86221,310,00017,251,00093,130,752
9Jun 24, 2024 20:194,82370,286,13321,945,00021,945,00093,081,600
10Jun 24, 2024 20:197,42498,325,97425,209,00042,351,00093,274,112
11Jun 24, 2024 20:197,44997,768,58224,922,00042,865,00093,208,576
12Jun 24, 2024 20:197,540101,920,84625,226,00043,389,00093,212,672