added python script to generate contexts

Fixed toJson
Added error messages, if decode from json failes.