I’m currently writing a CLI tool that handles a specific JSON data format. And I also want to give the user to get a slice of the item array of the file. It’s a slice in form of --slice START:END
through commandline options. So in example --slice 1:2
.
- Should I provide a 0 based index for the access or a 1 based index? In example
--slice 1:2
with 0 based index would start with the second element and with 1 based index it would start with the first element. - And would you think its better to have the
END
to be inclusive or exclusive? In example--slice 1:2
would get only one element if its exclusive or it gets two elements if its inclusive.
I know this is all personal taste, but I’m currently just torn between all options and cannot decide. And thought to ask you what you think. Maybe that helps me sorting my own thoughts a bit. Thanks in advance.
You’re writing a CLI tool to handle JSON data. Just making sure: You know
jq
exists, right?Right, but this tool does more than just what
jq
does. The file format has some specifics like default values in global header area for specific data and so on. it provides lot of special features optimized for the end file format that uses JSON data.Edit: To add an example what I mean is, JSON is like XML. It allows you to define a end format. JSON and XML are “encoded data”. Just being able to read JSON or XML is not enough to understand the format in its detail, if there are some complexities to it.