We will need to support building complex JSON structures in the command line in an intuitive way. To decouple this task from other tasks, we will actually build a different command that just builds the json structure and echos it to standard out.
This builds on the work of #8 to support a test-json command. Much of the way this works in the bash version is via using jq path parameters, so refreshing on jq and specifically the assignment operators may help https://stedolan.github.io/jq/manual/#Assignment or it may not.
The main way the interface works at this point, is that pass in , and we need to convert it into the right value.
Acceptance Criteria
epcc test-json foo bar => {"data":{"foo":"bar"}}
- Note that the keys are all embedded under a data tag.
epcc test-json foo.bar "hello world" ==> {"data":{"foo":{"bar":"hello world"}}}
- Note that x.y creates nested keys. Additionally note that the values are strings. You don't need to worry about parsing the " in this version, because the shell will take care of that, in the input to the program you will see a single string element with a space.
epcc test-json foo true ==> {"data":{"foo":true}}
- Note that here true, doesn't get quoted. This should also be true for numbers, as well as false and null.
epcc test-json foo \"true\" ==> {"data":{"foo":\"true\"}}
- Note when this runs, the program will have an array that contains the string "true" (6 characters). So the only logic the program has to do is optionally quote the value if it's not already quoted.
epcc test-json foo[0] "bar" ==> {"data":{"foo":["bar"]}}
- Note that we create an array here.
epcc test-json foo.bar [] ==> {"data":{"foo":{"bar":[]}}}
- Note here we are creating an empty array.
- I'd strongly recommend unit tests for this.
Maybe we want to look at https://github.com/itchyny/gojq which is a version of jq ported to go.
We will need to support building complex JSON structures in the command line in an intuitive way. To decouple this task from other tasks, we will actually build a different command that just builds the json structure and echos it to standard out.
This builds on the work of #8 to support a
test-jsoncommand. Much of the way this works in the bash version is via using jq path parameters, so refreshing onjqand specifically the assignment operators may help https://stedolan.github.io/jq/manual/#Assignment or it may not.The main way the interface works at this point, is that pass in , and we need to convert it into the right value.
Acceptance Criteria
epcc test-json foo bar=>{"data":{"foo":"bar"}}epcc test-json foo.bar "hello world"==>{"data":{"foo":{"bar":"hello world"}}}epcc test-json foo true==>{"data":{"foo":true}}epcc test-json foo \"true\"==>{"data":{"foo":\"true\"}}epcc test-json foo[0] "bar"==>{"data":{"foo":["bar"]}}epcc test-json foo.bar []==>{"data":{"foo":{"bar":[]}}}Maybe we want to look at https://github.com/itchyny/gojq which is a version of jq ported to go.