12-15-2017 07:02 AM
Hello,
I have written a script to create a JSON object with counters of a parameterized length, with the desired structure like this:
[
{
“counter”: 1
},
{
“counter”: 2
},
{
“counter”: 3
},
…
]
However, when I do this through a loop in a script snap, it puts the result in an extraneous array, like this:
[
[
{
“counter”: 1
},
{
“counter”: 2
},
{
“counter”: 3
},
…
]
]
Can anyone let me know why this is happening? I can’t get rid of the extra array using a structure or mapper snap either. My script looks like this:
def execute(self): self.log.info("Executing Transform script") list = [] for i in range(1,277): entry = {} entry["counter"] = i list.append(entry) output = list try: # Read the next document, wrap it in a map and write out the wrapper self.output.write(list) except Exception as e: errWrapper = { 'errMsg' : str(e.args) } self.log.error("Error in python script") self.error.write(errWrapper) self.log.info("Finished executing the Transform script")
Has anyone run into something like this before?
Thanks,
Jack
12-17-2017 12:04 PM
If that is really all you trying to do. You could achieve what you wanted with just the “Sequence” snap and it would create the structure you desire.
12-18-2017 08:50 AM
I wasn’t aware of that snap, thanks for bringing it to my attention.