Skip to content

Is it possible to set a Dataset property value in .dot notation with a dynamic property name ? JSON -> DataSet #1432

Answered by sscotti
sscotti asked this question in Q&A
Discussion options

You must be logged in to vote

Revisited this after quite a hiatus. This might actually be better because it can handle nested sequence and some other issues. Still need to really test it:

def getMWLFromJSON(MWLDict, DataSet):
    for key, value in MWLDict.items():
        if isinstance(value, str) or isinstance(value, int):
            setattr(DataSet, key, value)
        elif isinstance(value, list):
            # handle nested sequence
            sequence = []
            for i in range(len(value)):
                sequenceSet = Dataset()
                sequenceSet = getMWLFromJSON(value[i], sequenceSet)
                sequence.append(sequenceSet)
            setattr(DataSet, key, sequence)
        elif key in Da…

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@sscotti
Comment options

@darcymason
Comment options

@sscotti
Comment options

@sscotti
Comment options

Answer selected by sscotti
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants