How do I get RestClient in ruby to properly format responses with special characters?
<p>I have an array of objects I am sending to a REST API to receive back information on those objects. To do this I am using RestClient with the following lines to send the call and parse the response.</p>

<pre><code>response_raw = RestClient.get "http://#{re_host}:#{re_port}/reachengine/api/inventory/search?rql=fCSAssetNumber=#{fcs_id_num}%20size%20#{size}%20&amp;apiKey=#{api_key}", headers
 response_json = Crack::JSON.parse(response_raw)
 response_json['results'].each do |result|
</code></pre>

<p>For the first 20+ records I perform this action on, everything works fine. Then  I start to get a NoMethodError: undefined method `[]' for nil:NilClass</p>

<p>When I run the code step by step in IRB, what I see in the results is very strange</p>

<pre><code>result = response_json['results'][0]
&gt;=&gt; {"name"=&gt;"Publicaciòn_Listin_Diario.png", " id"=&gt;" 294290", " dateCreated"=&gt;" 2015-09-20T20:35:06.000+0000", " dateUpdated"=&gt;" 2015-12-23T19:33:13.000+0000", " systemKeywords"=&gt;" Publicaciòn_Listin_Diario.png Image ", "t humbnailId"=&gt;"4 24725", "m etadata"=&gt;{" sourceFilePath"=&gt;"/ Volumes/ONLINE_DAM/MEDIA/RAW_GRAPHICS/1307001_August_2013_KOS/Publicaciòn_Listin_Diario.png", "pa MdCustAgency_picklist_sortable"=&gt;"nul l", "th umbnailAssetFlag"=&gt;"fal se", "re storeKey"=&gt;"nul l", "ar chiveStatus_picklist_sortable"=&gt;"nul l", "fC SAssetNumber"=&gt;"18 2725", "fC SMetadataSet"=&gt;"Ra w Graphic", "cu stKeywords"=&gt;"Do minican Republic Cycling Team, 1307001 August 2013 KOS Kickoff show", "cu stAssetStatus_picklist_sortable"=&gt;"nul l", "se archableFlag"=&gt;"fal se", "as setType"=&gt;"Im age", "pa MdCustHerbalifeJobNumber"=&gt;"13 07001", "da teCreated"=&gt;"20 15-09-20T20:35:06", "da teLocked"=&gt;"nul l", "uu id"=&gt;"30 9d9bb3-6935-4ab6-a04a-ef7264132bc6", "ve rsionFlag"=&gt;"nul l", "ag ency_picklist_sortable"=&gt;"nul l", "pr oducer_picklist_sortable"=&gt;"nul l", "tr uncatedFlag"=&gt;"fal se", "cu stDescription"=&gt;"*R aw Graphics for 1307001_August_2013_KOS"}, "in ventoryKey"=&gt;"im age"}
</code></pre>

<p>Usually, with this response, I can run
    result['metadata']['fCSAssetNumber']</p>

<p>However; because of the random spaces, this fails with a "NoMethodError: undefined method `[]' for nil:NilClass" because instead of the string being 'metadata' it is actually 'm etadata'</p>

<p>Whats really strange about all of this and why this is a Ruby issue and not easily determined to be the API's issue is that the same exact call made via Postman REST Client in chrome returns this result:</p>

<pre><code>&gt;{
  "results": [
    {
      "name": "Publicaciòn_Listin_Diario.png",
      "id": "294290",
      "dateCreated": "2015-09-20T20:35:06.000+0000",
      "dateUpdated": "2015-12-23T19:33:13.000+0000",
      "systemKeywords": "Publicaciòn_Listin_Diario.png Image ",
      "thumbnailId": "424725",
      "metadata": {
        "sourceFilePath": "/Volumes/ONLINE_DAM/MEDIA/RAW_GRAPHICS/1307001_August_2013_KOS/Publicaciòn_Listin_Diario.png",
        "paMdCustAgency_picklist_sortable": null,
        "thumbnailAssetFlag": false,
        "restoreKey": null,
        "archiveStatus_picklist_sortable": null,
        "fCSAssetNumber": "182725",
        "fCSMetadataSet": "Raw Graphic",
        "custKeywords": "Dominican Republic Cycling Team, 1307001 August 2013 KOS Kickoff show",
        "custAssetStatus_picklist_sortable": null,
        "searchableFlag": false,
        "assetType": "Image",
        "paMdCustHerbalifeJobNumber": "1307001",
        "dateCreated": "2015-09-20T20:35:06",
        "dateLocked": null,
        "uuid": "309d9bb3-6935-4ab6-a04a-ef7264132bc6",
        "versionFlag": null,
        "agency_picklist_sortable": null,
        "producer_picklist_sortable": null,
        "truncatedFlag": false,
        "custDescription": "*Raw Graphics for 1307001_August_2013_KOS"
      },
      "inventoryKey": "image"
    }
  ],
  "total": "1"
}
</code></pre>

<p>Ad you can see above, when Postman runs the same exact call there is no issue with the response, but when ruby runs the call there is. Also note that this doesnt happen all of the time. </p>

<p>Below is a sample response from the same exact ruby call that actually worked. </p>

<pre><code>result = response_json['results'][0]
=&gt; {"name"=&gt;"Marco_1er_dia.png", "id"=&gt;"294284", "dateCreated"=&gt;"2015-09-`20T20:34:54.000+0000", "dateUpdated"=&gt;"2015-12-23T19:33:10.000+0000", "systemKeywords"=&gt;"Marco_1er_dia.png Image ", "thumbnailId"=&gt;"424716", "metadata"=&gt;{"sourceFilePath"=&gt;"/Volumes/ONLINE_DAM/MEDIA/RAW_GRAPHICS/1307001_August_2013_KOS/Marco_1er_dia.png", "paMdCustAgency_picklist_sortable"=&gt;nil, "collectionMemberships"=&gt;"320 321", "thumbnailAssetFlag"=&gt;false, "restoreKey"=&gt;nil, "fCSMetadataSet"=&gt;"Raw Graphic", "fCSAssetNumber"=&gt;"182722", "archiveStatus_picklist_sortable"=&gt;nil, "custAssetStatus_picklist_sortable"=&gt;nil, "custKeywords"=&gt;"1307001 August 2013 KOS Kickoff show, Dominican Republic Cycling Team", "searchableFlag"=&gt;false, "assetType"=&gt;"Image", "paMdCustHerbalifeJobNumber"=&gt;"1307001", "dateCreated"=&gt;"2015-09-20T20:34:54", "dateLocked"=&gt;nil, "uuid"=&gt;"b5e55c14-b94e-4629-9e2a-61a2dc0876f6", "versionFlag"=&gt;nil, "fCSProductionStatus_picklist_sortable"=&gt;nil, "agency_picklist_sortable"=&gt;nil, "producer_picklist_sortable"=&gt;nil, "truncatedFlag"=&gt;false, "custDescription"=&gt;"*Raw Graphics for 1307001_August_2013_KOS"}, "inventoryKey"=&gt;"image"}`
</code></pre>

<p>Notice how the response above has no spacing issue? The only glaring difference I can see here is that there is a special character in use in the filename: ò
Is there something specific I need to do for RESTClient to work with this?</p>

<p>Anyone have any idea how this can be fixed? </p>