Parse dynamic key in Json in Go

There is time, when we’re not sure what the key_name in json data will be. How do we do it in Go?

Donald Le

--

Photo by Paweł Czerwiński on Unsplash

We will use interface for the dynamic key.

For example the json value be like:

{
"TRPV6": {
"ncbi": {
"symbol": "",
"symbol_source": "",
"id": "",
"gene_name": "",
"gene_synonyms": null,
"biotype": "",
"contig": "",
"start": 0,
"end": 0,
"reference_genome": "",
"strand": "",
"description": ""
},
"ensembl": {
"symbol": "TRPV6",
"symbol_source": "ensembl_havana",
"id": "ENSG00000165125",
"gene_name": "TRPV6",
"gene_synonyms": [
"CaT1",
"ECAC2"
],
"biotype": "",
"contig": "chr7",
"start": 142871208,
"end": 142885745,
"reference_genome": "GRCh38",
"strand": "-",
"description": ""
},
"gene_cards": {
"symbol": "",
"id": "",
"gene_name": "",
"gene_synonyms": null,
"biotype": "",
"contig": ""…

--

--

Donald Le

A passionate automation engineer who strongly believes in “A man can do anything he wants if he puts in the work”.