Live data from Hacker News

Select, put and delete data from JSON, TOML, YAML, XML and CSV files

github.com

1–10 of 34 posts

Re: Select, put and delete data from JSON, TOML, YAML, XML and CSV files

#3
I think I prefer yq's[1] syntax for manipulating and updating fields.

Combined with yj[2] you can also get TOML and HCL support, but not CSV.

It's certainly not because there's a lack of these tools :p

[1]: https://github.com/mikefarah/yq

[2]: https://github.com/sclevine/yj

Re: Select, put and delete data from JSON, TOML, YAML, XML and CSV files

#8

The "delete" example on the readme is a bit odd, since it seems to suggest that you need to specify the value to delete as well as the path. The equivalent in the documentation does not have this problem.

Looks to be a mistake in the readme. The example in the docs doesn't have value being passed in.

> echo '{"name": "Tom"}' | dasel -p json '.name'

https://daseldocs.tomwright.me/usage/delete

Re: Select, put and delete data from JSON, TOML, YAML, XML and CSV files

#9

Can this or anything else flatten arrays of JSON objects to CSV?

I tend to use python (usually in a jupyter notebook) and pandas. Lots of experimentation with pandas' json_normalize() function. https://towardsdatascience.com/all-pandas-json-normalize-you...

then just call to_csv() on the dataframe. (edited to add to comment on exporting to CSV as per the original question).

Re: Select, put and delete data from JSON, TOML, YAML, XML and CSV files

#10

Can this or anything else flatten arrays of JSON objects to CSV?

Of course you can do it with http://brackit.io . What exactly is the "transformation" you envision?

Something like this (very simplified):

  let $array := [{"foo":0,"bar":"tztz"},{"foo":"hello","bar":null},{"foo":true,"bar":"yes"}]
  let $value := for $object in $array
                return
                  let $fields := bit:fields($object)
                  let $len := bit:len($fields)
  
                  for $field at $pos in $fields
                  return if ($pos $field || ","
                  ) else (
                    $object=>$field || "\n"
                  )
  return string-join($value,"")
will output:

  0,tztz
  hello,null
  true,yes
Post reply on HN