File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 22def tojson ($opts ): _to_json ($opts );
33def tojson : _to_json (null );
44# overrides jq's standard fromjson
5- # NOTE: should be kept in sync with format_decode.jq
6- def fromjson : decode ("json" ) | if ._error then error (._error.error ) end ;
5+ # NOTE:
6+ # should be kept in sync with format_decode.jq and can't use from_json as
7+ # it's not defined yet.
8+ # also uses tovalue on it's input to care of the where the input is a decode_value
9+ # string which without would end up decoding the "backing" binary instead.
10+ # Ex:
11+ # $ fq -n '"\"1,2,3\"" | fromjson | tobytes | tostring'
12+ # "\"1,2,3\""
13+ def fromjson : tovalue | decode ("json" ) | if ._error then error (._error.error ) end ;
714
815def _json__todisplay : tovalue ;
Original file line number Diff line number Diff line change 1+ # make sure fromjson decode from value instead of binary for a decode_value
2+ $ fq -n '"\"123\"" | fromjson | fromjson'
3+ 123
You can’t perform that action at this time.
0 commit comments