{"action":"created","issue":{"url":"https://api.github.com/repos/gvalkov/python-oneliner/issues/4","labels_url":"https://api.github.com/repos/gvalkov/python-oneliner/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/gvalkov/python-oneliner/issues/4/comments","events_url":"https://api.github.com/repos/gvalkov/python-oneliner/issues/4/events","html_url":"https://github.com/gvalkov/python-oneliner/issues/4","id":118507114,"number":4,"title":"Can't get simple multi-statement processing to work","user":{"login":"anjishnu","id":2019824,"avatar_url":"https://avatars.githubusercontent.com/u/2019824?v=3","gravatar_id":"","url":"https://api.github.com/users/anjishnu","html_url":"https://github.com/anjishnu","followers_url":"https://api.github.com/users/anjishnu/followers","following_url":"https://api.github.com/users/anjishnu/following{/other_user}","gists_url":"https://api.github.com/users/anjishnu/gists{/gist_id}","starred_url":"https://api.github.com/users/anjishnu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anjishnu/subscriptions","organizations_url":"https://api.github.com/users/anjishnu/orgs","repos_url":"https://api.github.com/users/anjishnu/repos","events_url":"https://api.github.com/users/anjishnu/events{/privacy}","received_events_url":"https://api.github.com/users/anjishnu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-24T00:44:39Z","updated_at":"2015-11-24T18:58:31Z","closed_at":null,"body":"I want to do something like:\r\n\r\n```python\r\nfor line in fileinput.input():\r\n j = json.loads(line)\r\n j['a'] = j['b'']\r\n print(json.dumps(j))\r\n```\r\n\r\nI tried statements like \r\n\r\n```bash\r\n$ cat file.txt | python -m oneliner -m json -pe \"j = json.loads(line); j['a'] = j['b']; print(json.dumps(j))\"\r\n```\r\n\r\nBut they all failed.\r\n"},"comment":{"url":"https://api.github.com/repos/gvalkov/python-oneliner/issues/comments/159372773","html_url":"https://github.com/gvalkov/python-oneliner/issues/4#issuecomment-159372773","issue_url":"https://api.github.com/repos/gvalkov/python-oneliner/issues/4","id":159372773,"user":{"login":"gvalkov","id":190997,"avatar_url":"https://avatars.githubusercontent.com/u/190997?v=3","gravatar_id":"","url":"https://api.github.com/users/gvalkov","html_url":"https://github.com/gvalkov","followers_url":"https://api.github.com/users/gvalkov/followers","following_url":"https://api.github.com/users/gvalkov/following{/other_user}","gists_url":"https://api.github.com/users/gvalkov/gists{/gist_id}","starred_url":"https://api.github.com/users/gvalkov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gvalkov/subscriptions","organizations_url":"https://api.github.com/users/gvalkov/orgs","repos_url":"https://api.github.com/users/gvalkov/repos","events_url":"https://api.github.com/users/gvalkov/events{/privacy}","received_events_url":"https://api.github.com/users/gvalkov/received_events","type":"User","site_admin":false},"created_at":"2015-11-24T18:58:31Z","updated_at":"2015-11-24T18:58:31Z","body":"Hi, can you try with the `-ns` flags? I got it working with:\r\n\r\n```bash\r\ncat <<EOF | python -m oneliner -m json -ns 'j=json.loads(line); j[\"a\"], j[\"b\"] = j[\"b\"], j[\"a\"]; print(json.dumps(j));' \r\n{\"a\": 1, \"b\": 2}\r\n{\"a\": 3, \"b\": 4}\r\nEOF\r\n{\"a\": 2, \"b\": 1}\r\n{\"a\": 4, \"b\": 3}\r\n```"}}