Skip to content

Improves castInput to allow any JSON object as attribute value #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2020

Conversation

usr-ein
Copy link
Contributor

@usr-ein usr-ein commented Apr 28, 2020

Following PR #15 , this introduces a better way to parse attribute values provided by the user. Does so by leveraging json.loads() ability to identify and convert into Python equivalent any JSON object, including complex values like lists, objects etc. Doesn't break current single atomic values conversion, i.e. type(json.loads("1")) == int, type(json.loads("true")) == bool, etc.

Before the suggested changes:

Current value of my_attr is: {'attr1': 'foo', 'attr2': 'bar'}
Please enter new value and hit ENTER
> {"attr1": "food", "attr2": "baz"}
[1] my_attr = "{'attr1': 'food', 'attr2': 'baz'}"   # This is a string and not an object !

And after

Current value of my_attr is: {'attr1': 'foo', 'attr2': 'bar'}
Please enter new value and hit ENTER
> {"attr1": "food", "attr2": "baz"}
[1] my_attr = {'attr1': 'food', 'attr2': 'baz'}  # This is a a JSON object, i.e. a Python dict

@ticarpi ticarpi merged commit 3264d2f into ticarpi:master May 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants