Skip to content

jokedewinter/companionplants

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Companion plants

Structure of the JSON file

This is not a real genuine JSON file, but a glorified JavaScript array pretending to be JSON. I have done it this way because it makes it less cumbersome to read the file (kind of).


var companions = [{
    "Angelica": {
        "+": ["Parsley"], 
        "-": ["Celery"], 
        "type": "Flower" }
    },{
    "Yarrow": {
        "+": ["Raspberry","Rosemary","Sweetcorn"], 
        "-": ["Rue"], 
        "type": "Herb" }
    },
] 

Fetching data

Because I chose not to have an extra bit in the data array for "id", the fetching of the individual plant names takes an extra index on the array name (or whatever you call that).


for ( var i = 0; i < companions.length; i++ ) {  
    for ( plant in companions[i] ) {
        console.log('Plant: ' + plant);
        console.log('Type: ' + companions[i][plant]['type']);
        console.log('Good: ' + companions[i][plant]['+']);
        console.log('Bad: ' + companions[i][plant]['-']);
    }
}

Releases

No releases published

Packages

No packages published