Question: yaml.load all requires space after ":" to recognize the right key. If it does not find the space it will use the whole key value pair as key and then give None as value.

See below: OP print has **'B2\_key:B2\_VAL': None** 

```
test_item = "A1: {B1_key: b1_val, B2_key:B2_VAL}"
yaml_iterator = yaml.load_all(test_item, Loader=yaml.Loader)
op = {}
for item in yaml_iterator:
    op.update(item)
print(op)

Output print: {'A1': {'B1_key': 'b1_val', 'B2_key:B2_VAL': None}}

```

I understand we can just have IP file in the right format. But is there a way we can handle it? i want users to not be care about spaces. 

One way can be to inspect the the OP dict and handle it there.

Please advice best way to handle this. Thanks in advance.

Answer: 
The [YAML syntax](https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html) explicitly states that a colon must be followed by a space. You therefore have two options:

1. Require your users to write in YAML (even if that means they have to add a space after the colon when specifying keys); or,
2. Use a half-thought-out format somewhat resembling YAML, for which you do not have a parser already built, and which does not allow keys with a colon in them.

**Go with option 1**.
If you really don't want your users to care about the syntax and you have the yaml in a string, you could add spaces after the semicolons:

```
test_item = test_item.replace(':', ': ')

```

Output:

```
{'A1': {'B1_key': 'b1_val', 'B2_key': 'B2_VAL'}}

```

But this would only work if semicolons are not allowed in the keys and values.