LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
175 stars 31 forks source link

Worng coulmn values in conversion #361

Closed eirtech closed 5 years ago

eirtech commented 5 years ago

Hi, In the conversion procedure by the command to CSV some columns filled with the wrong variables in all the cells. something like: ARRAY(0x481b460) or HASH(0x481b640) is there something related to the options which I should set?

jorol commented 5 years ago

Hey,

you can't export complex data structures to a single CSV field. You should use Catmandu::Fix to flatten or map your data:

$ echo '{ "key":"value", "array":["a","b","c"], "hash":{"a":1,"b":2,"c":3} }' | catmandu convert JSON to CSV --fix 'copy_field(array.0,my_first_array_value);copy_field(hash.a,my_first_hash_value)' --fields key,my_first_array_value,my_first_hash_value
key,my_first_array_value,my_first_hash_value
value,a,1

See also our cheat sheet.

eirtech commented 5 years ago

Thank you so much for your quick response. So, is there also an option to copy the whole array to separated columns? I get the point that it can be read the whole array by ( .* ) but I don't know how I can append these columns as array1, array2, ...... columns.

nics commented 5 years ago

Hi, that's not possible. You can split the array value split_field(array, '|'). Or if the array is short: copy_field(array.0, arr_0) copy_field(array.1, arr_1) copy_field(array.2, arr_2)

eirtech commented 5 years ago

Hmm, I thought split_field workes in the opposite way. Actually, the array is not short. Would you please tell me how split_field works?

nics commented 5 years ago

Sorry, I meant join_field

On Thu, 7 Mar 2019, 16:56 Elham Iravani, notifications@github.com wrote:

Hmm, I thought split_field workes in the opposite way. Actually, the array is not short. Would you please tell me how split_field works?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/LibreCat/Catmandu/issues/361#issuecomment-470582108, or mute the thread https://github.com/notifications/unsubscribe-auth/AACKXQBMxT_vsI7bOEwZu8ujCJLfTdUCks5vUTabgaJpZM4bixHn .

eirtech commented 5 years ago

Thanks.