Skip to content
Advertisement

How can I insert an array into a specific array element using Jolt

Question/problem

How can I use Jolt to insert an array into a specific object in an array?

input

The objects have a common set of attributes, but support optional attributes.

Specific objects need to get these optional attributes depending on their specific position in the array, i.e. second ([1]). These optional attributes are to be added as part of the jolt transformation.

JavaScript

expected

JavaScript

What has been tried

I’ve tried default, modify-default-beta, and modify-overwrite-beta and none seem to behave the way I thought they did.

default

Seems like default ignores the array reference "[1]" so tried the beta operations which seem to support this.

default spec

JavaScript

default actual

JavaScript

modify-default-beta

Resolves the array reference "[1]", but only applies the first element in the array from the spec and not the whole array

modify-default-beta spec

JavaScript

modify-default-beta actual

JavaScript

modify-overwrite-beta

Tried modify-overwrite-beta and I get the same behaviour as modify-default-beta.

modify-overwrite-beta spec

JavaScript

modify-overwrite-beta actual

JavaScript

Interesting side note

Without the array reference on the input this is a fairly easy problem, it seems the behaviour is not what I am expecting when there is an array reference and the *-beta operations.

simple default

I’ve gotten rid of the array from the input

simple default input

JavaScript

simple default spec

JavaScript

simple default actual

JavaScript

Advertisement

Answer

This appears to be my misunderstanding of the usage of the spec.

It appears that you don’t insert an array, but each element that you want to insert.

JavaScript

The spec above is inserting both values into the values attribute and specifically into element "[0]" and element "[1]".

This also works with the modify-overwrite-beta operation

JavaScript

the result of both of these specs is as follows:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement