fork download
  1. import json
  2. import sys
  3.  
  4. foo = '{"My_string": "Foo bar.\\t Bar foo."}'
  5. print(repr(json.loads(foo)))
  6.  
  7. foo = r'{"My_string": "Foo bar.\t Bar foo."}'
  8. print(repr(json.loads(foo)))
  9.  
  10. print(repr(json.load(sys.stdin)))
  11.  
  12. foo_invalid = '{"My_string": "Foo bar.\t Bar foo."}'
  13. try:
  14. json.loads(foo_invalid)
  15. except ValueError:
  16. print("ok")
  17. else:
  18. assert 0
Success #stdin #stdout 0.04s 9792KB
stdin
{"My_string": "Foo bar.\t Bar foo."}
stdout
{'My_string': 'Foo bar.\t Bar foo.'}
{'My_string': 'Foo bar.\t Bar foo.'}
{'My_string': 'Foo bar.\t Bar foo.'}
ok