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

Allow JSON schema output indentation to be configurable #439

Closed
sprak3000 opened this issue Feb 13, 2023 · 6 comments
Closed

Allow JSON schema output indentation to be configurable #439

sprak3000 opened this issue Feb 13, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@sprak3000
Copy link

Currently, the JSON schema can be generated in two ways but with different indentation of the output. Running tbls doc results in the output file containing no indentation, just a single string of JSON. Running tbls out -t json results in an output file where the JSON is indented making it easier to read. It would be helpful to have a configuration option allowing both commands to either indent or not based on its value.

The OutputSchema function controls this behavior via an inline parameter on the JSON struct. The out command passes in false. The doc command passes in true. Both appear to have access to the configuration.

Seems like a straightforward change with the only question in my mind is if there should be two separate configuration items to allow you to configure both commands separately or just one that both commands use.

@sprak3000 sprak3000 added the enhancement New feature or request label Feb 13, 2023
sprak3000 added a commit to sprak3000/tbls that referenced this issue Feb 13, 2023
…able

 - Add `inlineJSON` boolean configuration field to the `Format` struct. Include this field in the YAML marshal / unmarshal functions.
 - Update the uses of `json.New()` to use the value from the configuration.
 - Update `README` to contain the new configuration field.
@k1LoW
Copy link
Owner

k1LoW commented Feb 13, 2023

@sprak3000 Thank you for your comment!

The JSON of tbls out is indented because it is the final output, but the schema.json of tbls doc is not indented because it is metadata.

It would be helpful to have a configuration option allowing both commands to either indent or not based on its value.

Are there any use cases where this would be helpful?

(I don't particularly care about indentation as I believe the jq command has become common.)

@sprak3000
Copy link
Author

@k1LoW

The JSON of tbls out is indented because it is the final output, but the schema.json of tbls doc is not indented because it is metadata.

Conceptually, what is the difference between the two for you? I put together a quick PR around this to output both indented. I cannot see any difference between the two outputs; they result in the same JSON structure.

Are there any use cases where this would be helpful?

My use case is checking these files into a repo as documentation and being able to quickly and easily see the differences in a PR. Currently, our pipeline creates the file using tbls doc resulting in the inline version. Trying to read a diff of a single, lengthy line of JSON isn't pleasant.

believe the jq command has become common

It is, but this tool could do the same meaning one less dependency. Regardless, thank you very much for creating and maintaining this tool!

@k1LoW
Copy link
Owner

k1LoW commented Feb 14, 2023

My use case is checking these files into a repo as documentation and being able to quickly and easily see the differences in a PR. Currently, our pipeline creates the file using tbls doc resulting in the inline version. Trying to read a diff of a single, lengthy line of JSON isn't pleasant.

fmfm. So what about changing the schema.json of tbls doc to indented output?
I don't think we need a specific option to change it to inline ( because I use jq ).

@sprak3000
Copy link
Author

fmfm. So what about changing the schema.json of tbls doc to indented output? I don't think we need a specific option to change it to inline ( because I use jq ).

I'd be fine with that, but I'm also fine leaving it as is and adding jq into our process. We typically have it on hand, so it isn't a large lift. Feel free to close this out if you like and / or close out my PR.

Thank you again!

Cheers.

@k1LoW
Copy link
Owner

k1LoW commented Feb 15, 2023

@sprak3000 Thank you. I'll think about indentation again.

@awhitford-cip
Copy link

awhitford-cip commented Apr 24, 2023

My use case is checking these files into a repo as documentation and being able to quickly and easily see the differences in a PR. Currently, our pipeline creates the file using tbls doc resulting in the inline version. Trying to read a diff of a single, lengthy line of JSON isn't pleasant.

This is my use case too.
Requiring an extra step to use JQ seems silly when there is a flag available in the go library.
Maybe adding an option in .tbls.yml would make better sense to satisfy us.

Having said that, my workaround was to simply disable the schema.json file using: disableOutputSchema: true

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

No branches or pull requests

3 participants