Skip to content

Instantly share code, notes, and snippets.

@jiaxianhua
Created April 4, 2019 01:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiaxianhua/23c5fcef8cd114057a0dfb8190de273a to your computer and use it in GitHub Desktop.
Save jiaxianhua/23c5fcef8cd114057a0dfb8190de273a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import collections
def readMd(mdfile):
with open(mdfile) as f:
lines = f.readlines()
lines = list(map(lambda l: l.rstrip(), lines))
d = collections.OrderedDict({line: '' for line in lines})
json_str = json.dumps(d)
return json_str
def readJson(json_str):
ordered_dict = json.loads(json_str, object_pairs_hook=collections.OrderedDict)
print(ordered_dict)
if __name__ == '__main__':
json_str = readMd('README.md')
readJson(json_str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment