Building factor and subfactor JSON