vovatalking.blogg.se

Jq convert string to number
Jq convert string to number









jq convert string to number

> jq -r don't consider myself much of a jq power user, but I am a huge admirer of its capabilities. We echo a simple JSON string and pipe it directly into our jq command. $ jq -cR 'split(",")' foo.csv | jq -csf csv2json.jq | \ $ jq -R 'split(",")' foo.csv | jq -sr to turn the fuller structure from the third example back into CSV, you can pick out the fields, albeit this one is less friendly with quotes and doesn't spit out a header (probably doable by calling `keys` on `.` only.): This can be use with the second example above to say "turn each array into a CSV row" like so: In the reverse direction there's a builtin format string. Note that this recipe also keeps numbers as numbers! You can use the JavaScript split() method to split a string using a specific separator such as comma (, ), space, etc. It's a very dense, terse syntax in a DSL with implicit looping constructs.

Jq convert string to number code#

It just struck me that the complaints about Perl regex line noise over the past 10 or 20 years, or comments about impenetrable APL code years ago would equally apply to jq nowadays. $ jq -cR 'split(",")' foo.csv | jq -csf csv2json.jq No, your answer is pretty good about explaining the jq constructs you're using. ,]Īnd if you prefer objects, this output can be combined with the csv2json recipe from the jq cookbook, without requiring `any-json` or any other external tool: Pipe that back to `jq` in slurp mode, though: if you don't mind numbers ending up as strings).įirst attempt is to simply read each line in as raw and split on `,` - sort of does the job of, but it isn't the array of arrays that you might expect: The function takes many different data types: BINARYFLOAT BINARYDOUBLE CHAR VARCHAR2 NCHAR NVARCHAR2 The TONUMBER returns a value in the NUMBER data type. Tip: For an example action using this filter, refer to ZIS action: Converting a number to a string. The following expression changes the ticket id value to a string. It works similar to the TODATE and TOCHAR functions but converts the values to a number. Use the tostring filter to convert a non-string value to a string. `jq` can transform CSV to JSON and vice-versa, especially for simple/naive data where simply splitting on `,` is good enough - and where you aren't too bothered by types (e.g. The Oracle TONUMBER function is used to convert a text value to a number value.











Jq convert string to number