Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jo will drop the trailing newline at the end of file #199

Open
tw4452852 opened this issue Aug 3, 2023 · 8 comments
Open

jo will drop the trailing newline at the end of file #199

tw4452852 opened this issue Aug 3, 2023 · 8 comments

Comments

@tw4452852
Copy link

tw4452852 commented Aug 3, 2023

> echo foo > test.txt
> jo '[email protected]'
{"test":"foo"}

The manual says:

@file substitute the contents of file as-is

Why the trailing newline is stripped when processing? I expect jo should leave the content string the same as the file content.
BTW, the code is here:

jo/jo.c

Line 350 in b3e67e1

if (*bp == '\n') *bp-- = 0;

@jpmens
Copy link
Owner

jpmens commented Aug 3, 2023

It made sense to me/us to have that stripped.

Why would you not want it stripped?

@jpmens
Copy link
Owner

jpmens commented Aug 3, 2023

We should probably amend the description in the man page.

@tw4452852
Copy link
Author

tw4452852 commented Aug 3, 2023

But I want to make a json with the exact content of a file as it-is. Could I archieve this with jo? Maybe we could add a option (like -raw)?

@jpmens
Copy link
Owner

jpmens commented Aug 3, 2023

The only solution which occurs to me right now is to transport with base64 and then decode on the receiving end:

$ echo hello > test.txt
$ jo 'test=%test.txt'
{"test":"aGVsbG8K"}
$ echo aGVsbG8K | base64 -d
hello
$ echo aGVsbG8K | base64 -d | od -cb
0000000    h   e   l   l   o  \n
          150 145 154 154 157 012
0000006

@tw4452852
Copy link
Author

Really hope jo could add an option to support reading the raw content of a file as a string.

@isotopp
Copy link
Contributor

isotopp commented Aug 3, 2023

It made sense to me/us to have that stripped.

Why would you not want it stripped?

It would invalidate any checksum or signature on the content of that file.

@gromgit
Copy link
Collaborator

gromgit commented Aug 4, 2023

Since trimming the output has been the default operation for years with no complaints until now, it might not be desirable to unilaterally switch to verbatim inclusion mode by default.

I guess we could add a -l (for literal) switch, and document current behavior.

@jpmens
Copy link
Owner

jpmens commented Aug 6, 2023

I'm not hugely in favor of a switch to toggle that behaviour. Would a separate character make sense? <filename, reminischent of shell input.

BTW, if we do implement this, the underlying JSON routines will not handle binary zero \00, so I'm not sure how useful this would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants