# Buggy code
def load_lockfile(self, expand_env_vars=True):
    with io.open(self.lockfile_location) as lock:
        j = json.load(lock)
        self._lockfile_newlines = preferred_newlines(lock)
    # lockfile is just a string
    if not j or not hasattr(j, "keys"):
        return j

    if expand_env_vars:
        # Expand environment variables in Pipfile.lock at runtime.
        for i, source in enumerate(j["_meta"]["sources"][:]):
            j["_meta"]["sources"][i]["url"] = os.path.expandvars(
                j["_meta"]["sources"][i]["url"]
            )

    return j


# Traceback (TypeError)
[I] ~/test $ pipenv --version
pipenv, version 2018.7.1
[I] ~/test $ ll
total 8
-rw-r--r--  1 jacobhayes    96B Jul  3 13:12 Pipfile
[I] ~/test $ cat Pipfile
[packages]
requests = {git = "https://github.com/requests/requests.git", extras = ["security"]}
[I] ~/test $ pipenv --rm ; pipenv install --verbose
Removing virtualenv (/Users/jacobhayes/.local/share/virtualenvs/test-qFl43Lkt)...
Creating a virtualenv for this project...
Pipfile: /Users/jacobhayes/test/Pipfile
Using /usr/local/opt/python/bin/python3.6 (3.6.5) to create virtualenv...
⠋Already using interpreter /usr/local/opt/python/bin/python3.6
Using base prefix '/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/jacobhayes/.local/share/virtualenvs/test-qFl43Lkt/bin/python3.6
Also creating executable in /Users/jacobhayes/.local/share/virtualenvs/test-qFl43Lkt/bin/python
Installing setuptools, pip, wheel...done.
Setting project for test-qFl43Lkt to /Users/jacobhayes/test

Virtualenv location: /Users/jacobhayes/.local/share/virtualenvs/test-qFl43Lkt
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Traceback (most recent call last):
File "/usr/local/bin/pipenv", line 11, in <module>
sys.exit(cli())
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/pipenv/cli.py", line 435, in install
selective_upgrade=selective_upgrade,
File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 1943, in do_install
pypi_mirror=pypi_mirror,
File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 1312, in do_init
pypi_mirror=pypi_mirror,
File "/usr/local/lib/python3.6/site-packages/pipenv/core.py", line 1140, in do_lock
project.write_lockfile(lockfile)
File "/usr/local/lib/python3.6/site-packages/pipenv/project.py", line 648, in write_lockfile
content, indent=4, separators=(u',', u': '), sort_keys=True,
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 238, in dumps
**kw).encode(obj)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 201, in encode
chunks = list(chunks)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 430, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 404, in _iterencode_dict
yield from chunks
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 437, in _iterencode
o = _default(o)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'ArrayElement' is not JSON serializable

# Fixed code
def load_lockfile(self, expand_env_vars=True):
    with io.open(self.lockfile_location, encoding="utf-8") as lock:
        j = json.load(lock)
        self._lockfile_newlines = preferred_newlines(lock)
    # lockfile is just a string
    if not j or not hasattr(j, "keys"):
        return j

    if expand_env_vars:
        # Expand environment variables in Pipfile.lock at runtime.
        for i, source in enumerate(j["_meta"]["sources"][:]):
            j["_meta"]["sources"][i]["url"] = os.path.expandvars(
                j["_meta"]["sources"][i]["url"]
            )

    return j