Created
          May 10, 2022 13:22 
        
      - 
      
- 
        Save arbakker/b92136c5e46819da868a674c5921c7e8 to your computer and use it in GitHub Desktop. 
    remap json keys with jq #jq #json
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // remap json keys with following mapping table and remove null and empty string values | |
| // { | |
| // "name": "n", | |
| // "title": "t", | |
| // "abstract": "a", | |
| // "tilematrixsets": "tms", | |
| // "imgformats": "if", | |
| // "dataset_md_id": "dmi", | |
| // "service_title": "sti", | |
| // "service_url": "su", | |
| // "service_type": "sty", | |
| // "service_abstract": "sa", | |
| // "service_md_id": "smi" | |
| // } | |
| inputfile=pdokservicesplugin/resources/layers-pdok.json;jq -c '[.[] | . + { "n": .name, "t": .title, "a": .abstract, "tms": .tilematrixsets, "if": .imgformats, "dmi": .dataset_md_id, "sti": .service_title, "su": .service_url, "sty": .service_type, "sa": .service_abstract, "smi": .service_md_id} | del(.name) | del(.title) | del(.abstract) | del(.tilematrixsets) | del(.imgformats) | del(.dataset_md_id) | del(.service_title) | del(.service_url) | del(.service_type) | del(.service_abstract) | del(.service_md_id)]' < "$inputfile" | jq -c '[.[] | with_entries( select( .value != "" and .value != null ))]' | sponge "$inputfile" | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment