Re: jolt array name to attribute?

2020-01-16 Thread Matt Burgess
My original spec flattens everything to the top level. If instead you
want to associate each field in the top-level object with its own
properties (just move the key inside as the value of "type"), you can
use the following spec:

[
  {
"operation": "shift",
"spec": {
  "*": {
"$": "[#2].type",
"*": {
  "*": "[#3].&"
}
  }
}
  }
]

This doesn't give you the desired output you recently described
(keeping the top-level key in place as well as moving it inside as the
value of "type"), did you want the output as you described in your
original email, or in the latest one?

Regards,
Matt

On Thu, Jan 16, 2020 at 11:01 AM l vic  wrote:
>
> Hi Matt,
> Is it possible with modify-default-beta? The problem with "shift" solution - 
> it doesn't work if i have several arrays within my struct:
> {
>  "HomeAddress": [
> {
>  "Street": "Washington St",
>  "ZIP": "03420",
>  "unit": "1"
> }
> ],
> "BusinessAddress": [
> {
>  "Street": "PO Box 22",
>  "ZIP": "03420",
>  "unit": "none"
> }
> ]
> }
>
> Result:
> {
>   "type" : [ "HomeAddress", "BusinessAddress" ],
>   "Street" : [ "Washington St", "PO Box 22" ],
>   "ZIP" : [ "03420", "03420" ],
>   "unit" : [ "1", "none" ]
> }
>
> Desired result:
> {
>  "HomeAddress": [
> {
>  "Street": "Washington St",
>  "ZIP": "03420",
>  "unit": "1",
> "type": "HomeAddress"
> }
> ],
> "BusinessAddress": [
> {
>  "Street": "PO Box 22",
>  "ZIP": "03420",
>  "unit": "none",
> "type": "BusinessAddress"
> }
> ]
> }
>
> On Wed, Jan 15, 2020 at 3:29 PM Matt Burgess  wrote:
>>
>> Try the following chain spec:
>>
>> [
>>   {
>> "operation": "shift",
>> "spec": {
>>   "*": {
>> "$": "type",
>> "*": {
>>   "*": "&"
>> }
>>   }
>> }
>>   }
>> ]
>>
>> This will "flatten" any key with an array value into a "type" field
>> with the name of the array key, and all its entries as top-level
>> fields.
>>
>> Regards,
>> Matt
>>
>>
>> On Wed, Jan 15, 2020 at 2:52 PM l vic  wrote:
>> >
>> > i have input json such as the following example:
>> > {
>> >  "Address": [
>> > {
>> >  "Street": "Washington St",
>> >  "ZIP": "03420",
>> >  "unit": "1"
>> > }
>> > ]
>> > }
>> > How can i use Jolt transform to add array name as attribute value to
>> > array members as following result:
>> > {
>> > "type": "Address",
>> > "Street": "Washington St",
>> >  "ZIP": "03420",
>> >  "unit": "1"
>> > }
>> > Thank you,


Re: jolt array name to attribute?

2020-01-16 Thread l vic
Hi Matt,
Is it possible with modify-default-beta? The problem with "shift" solution
- it doesn't work if i have several arrays within my struct:
{
 "HomeAddress": [
{
 "Street": "Washington St",
 "ZIP": "03420",
 "unit": "1"
}
],
"BusinessAddress": [
{
 "Street": "PO Box 22",
 "ZIP": "03420",
 "unit": "none"
}
]
}

Result:
{
  "type" : [ "HomeAddress", "BusinessAddress" ],
  "Street" : [ "Washington St", "PO Box 22" ],
  "ZIP" : [ "03420", "03420" ],
  "unit" : [ "1", "none" ]
}

Desired result:
{
 "HomeAddress": [
{
 "Street": "Washington St",
 "ZIP": "03420",
 "unit": "1",
"type": "HomeAddress"
}
],
"BusinessAddress": [
{
 "Street": "PO Box 22",
 "ZIP": "03420",
 "unit": "none",
"type": "BusinessAddress"
}
]
}

On Wed, Jan 15, 2020 at 3:29 PM Matt Burgess  wrote:

> Try the following chain spec:
>
> [
>   {
> "operation": "shift",
> "spec": {
>   "*": {
> "$": "type",
> "*": {
>   "*": "&"
> }
>   }
> }
>   }
> ]
>
> This will "flatten" any key with an array value into a "type" field
> with the name of the array key, and all its entries as top-level
> fields.
>
> Regards,
> Matt
>
>
> On Wed, Jan 15, 2020 at 2:52 PM l vic  wrote:
> >
> > i have input json such as the following example:
> > {
> >  "Address": [
> > {
> >  "Street": "Washington St",
> >  "ZIP": "03420",
> >  "unit": "1"
> > }
> > ]
> > }
> > How can i use Jolt transform to add array name as attribute value to
> > array members as following result:
> > {
> > "type": "Address",
> > "Street": "Washington St",
> >  "ZIP": "03420",
> >  "unit": "1"
> > }
> > Thank you,
>


Re: jolt array name to attribute?

2020-01-15 Thread Matt Burgess
Try the following chain spec:

[
  {
"operation": "shift",
"spec": {
  "*": {
"$": "type",
"*": {
  "*": "&"
}
  }
}
  }
]

This will "flatten" any key with an array value into a "type" field
with the name of the array key, and all its entries as top-level
fields.

Regards,
Matt


On Wed, Jan 15, 2020 at 2:52 PM l vic  wrote:
>
> i have input json such as the following example:
> {
>  "Address": [
> {
>  "Street": "Washington St",
>  "ZIP": "03420",
>  "unit": "1"
> }
> ]
> }
> How can i use Jolt transform to add array name as attribute value to
> array members as following result:
> {
> "type": "Address",
> "Street": "Washington St",
>  "ZIP": "03420",
>  "unit": "1"
> }
> Thank you,