This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

34 řádky
828 B

  1. import json
  2. from .json_parser import json_grammar
  3. from lark import Lark
  4. from lark.reconstruct import Reconstructor
  5. def test():
  6. test_json = '''
  7. {
  8. "empty_object" : {},
  9. "empty_array" : [],
  10. "booleans" : { "YES" : true, "NO" : false },
  11. "numbers" : [ 0, 1, -2, 3.3, 4.4e5, 6.6e-7 ],
  12. "strings" : [ "This", [ "And" , "That" ] ],
  13. "nothing" : null
  14. }
  15. '''
  16. json_parser = Lark(json_grammar)
  17. tree = json_parser.parse(test_json)
  18. # print '@@', tree.pretty()
  19. # for x in tree.find_data('true'):
  20. # x.data = 'false'
  21. # # x.children[0].value = '"HAHA"'
  22. new_json = Reconstructor(json_parser).reconstruct(tree)
  23. print new_json
  24. print json.loads(new_json) == json.loads(test_json)
  25. test()