json: avoid repeating if condition