# unicode, json...

**URL:** <https://forum.ansible.com/t/unicode-json/28486>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [September 1, 2018, 5:12am UTC](https://forum.ansible.com/t/unicode-json/28486 "2018-09-01T05:12:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 1, 2018, 5:12am UTC](https://forum.ansible.com/t/unicode-json/28486/1 "2018-09-01T05:12:30Z")

</div>

I have an AWS CLI command that returns this (I’ve truncated it):

changed: [localhost] =\> {“changed”: true, “cmd”: [“aws”, “elbv2”, “create-load-balancer”, “–name”, “ADFS-ext-nlb”, “–type”, “network”, “–subnet-mappings”, "SubnetId=subnet-c1580ba5,AllocationId=eipalloc-09644c10a5aac6a39 SubnetId=subnet-3cd85265,AllocationId=eipalloc-09c95f8e4f8e111b2 "], “delta”: “0:00:02.343846”, “end”: “2018-09-01 14:13:21.199441”, “rc”: 0, “start”: “2018-09-01 14:13:18.855595”, “stderr”: “”, “stderr\_lines”: , “stdout”: "{\n "LoadBalancers": [\n {\n "Scheme": "internet-facing",\n "State": {\n "Code": "active"\n },\n "DNSName": "[ADFS-ext-nlb-722a4422c412e03e.elb.ap-southeast-2.amazonaws.com](http://ADFS-ext-nlb-722a4422c412e03e.elb.ap-southeast-2.amazonaws.com)",\n

I have converted it into json like this:

- set\_fact:  
nlb: " {{ nlb.stdout |from\_json }}"

And the output from that is this:

TASK [nlb : set\_fact] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {“ansible\_facts”: {“nlb”: " {u’LoadBalancers’: [{u’IpAddressType’: u’ipv4’, u’Scheme’: u’internet-facing’, u’LoadBalancerArn’: u’arn:aws:elasticloadbalancing:ap-southeast-2:375939078089:loadbalancer/net/ADFS-ext-nlb/722a4422c412e03e’, u’VpcId’: u’vpc-8bc156ef’, u’State’: {u’Code’: u’active’}, u’DNSName’: u’[ADFS-ext-nlb-722a4422c412e03e.elb.ap-southeast-2.amazonaws.com](http://ADFS-ext-nlb-722a4422c412e03e.elb.ap-southeast-2.amazonaws.com)’, u’LoadBalancerName’: u’ADFS-ext-nlb’, u’CreatedTime’: u’2018-09-01T03:10:47.036Z’, u’AvailabilityZones’: [{u’SubnetId’: u’subnet-c1580ba5’, u’ZoneName’: u’ap-southeast-2b’, u’LoadBalancerAddresses’: [{u’IpAddress’: u’52.64.194.159’, u’AllocationId’: u’eipalloc-09c95f8e4f8e111b2’}]}], u’Type’: u’network’, u’CanonicalHostedZoneId’: u’ZCT6FZBF4DROD’}]} "}, “changed”: false}

I want to extract a LoadBalancerArn from that, but I can’t seem to refer to the internal structure. I won’t list here all the various syntactical variations I’ve tried! What I want is something like this:

- set\_fact:

lb\_arn: “{{ nlb.LoadBalancers[0].LoadBalancerArn }}”

No matter what I try I always get something like this:

fatal: [localhost]: FAILED! =\> {“msg”: “‘ansible.utils.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘LoadBalancers’”}

Is this because of the unicode? Or am I missing something else?

Regards, K.

---

<div class="post-metadata">

**Author:** ![tkuratom](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@tkuratom](https://forum.ansible.com/u/tkuratom)\
**Post date:** [September 1, 2018, 6:06am UTC](https://forum.ansible.com/t/unicode-json/28486/2 "2018-09-01T06:06:39Z")

</div>

It appears that nlb contains a string. Perhaps because of the initial space in

```auto
nlb: " {{ nlb.stdout |from_json }}"

```

?

---

<div class="post-metadata">

**Author:** ![Karl\_Auer](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@Karl\_Auer](https://forum.ansible.com/u/Karl_Auer)\
**Post date:** [September 1, 2018, 6:15am UTC](https://forum.ansible.com/t/unicode-json/28486/3 "2018-09-01T06:15:54Z")

</div>

Thank you!

It all suddenly worked and I had no idea why, then you pointed out the space and the light dawned. I’d removed the space, but without realising it was significant. Also, I worked out that the I needed to treat the response from AWS as yaml, not json - that got rid of the unicode stuff.

Thanks again.

I wonder if I will ever NOT be a noob at this stuff… sigh.

Regards, K.
