(aka “how to get almost canonical output” with custom JsonNodeFactory) TL DNR: quick way to get it “all sorted out” NB – If you save the modified content it will be saved using the new sorted format.Jackson Tips: sorting JSON using JsonNode Final thoughtsĬustom file types don’t just affect comparisons – If you right click on a file and choose Open With, Text Edit you will also see the sorted version of the file – not the original. In addition Beyond Compare allows line weighting within the algorithm so that it can assign preferential weights to certain grammar elements, although this has not been particularly fruitful when used according to the example below. I would like to investigate whether it’s possible to define a template format in yq so that it uses a custom key alignment order so that it matches the specification used by the Kubernetes API. There’s much more that you can do with both yq and Beyond Compare to further tune the formatting order, but hopefully this gives you some sort of light at the end of the tunnel when attempting comparisons of YAML documents. Resulting file comparison between left and right – after sorting via yq I think you’ll agree that it’s much easier to spot the differences and also allow standardisation of your files going forward. Here is the resulting comparison after processing with yq. yq e -M -P "keys" C:\Users\stwa\desktop\example-ingress1.yaml Now open a YAML file comparison and you’ll find a much improved alignment based upon first the sorting of individual keys, then subsequent scalar values within each.Į.g. The executable takes the input file ( %1) then sorts the keys and values alphabetically in sequence first before outputting the content to a new temporary file ( %2). In the background it will run the yq executable twice (via the batch file), once for each input file (left and right comparison). It will use the file type mask to apply the custom file format you just created. Now find two YAML files to compare and double click in Beyond Compare. Optionally, choose whether to Disable editing (when displaying the resulting comparison) and whether to ‘Trim trailing whitespace’ when saving – I find this helpful sometimes.Ĭlick on the Misc tab and choose ‘Insert spaces instead of tabs’ and tab stop 8. *.yaml,*.ymlĬlick on the Conversion tab and select External program (Unicode filenames) then enter the following path and parameters On the General tab enter a file mask to use when applying the File Format correctly, e.g.
0 Comments
Leave a Reply. |