Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8819591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:23:56+00:00 2026-06-14T05:23:56+00:00

I’m working with a YAML file, and when I convert it to a hash,

  • 0

I’m working with a YAML file, and when I convert it to a hash, one of the values is a string.

This is the document I’m working with:

---
    http_interactions:
    - request:
        method: post
        uri: http://********/client/api
        body:
          encoding: US-ASCII
          string: *******************
        headers: {}

      response:
        status:
          code: 200
          message: OK
        headers:
          Date:
          - Mon, 24 Sep 2012 10:38:01 GMT
          Set-Cookie:
          - ***************; Path=/client
          Content-Type:
          - text/javascript;charset=UTF-8
          Content-Length:
          - "425"
        body:
          encoding: ASCII-8BIT
          string: >
            {
              "loginresponse": {
                "timeout": "43200",
                "lastname": "frgrg",
                "registered": "false",
                "username": "rfrfr",
                "timezone": "America\/New_York",
                "firstname": "Mrfrfronika ",
                "domainid": "3434444444444444444",
                "type": "0",
                "userid": "4444444444444444444444444444444441",
                "sessionkey": "ewrffffffffffffffffffffff",
                "timezoneoffset": "-4.0",
                "account": "dddd"
              }
            }
        http_version:
      recorded_at: Mon, 24 Sep 2012 10:38:01 GMT
    recorded_with: VCR 2.2.5

This is how I work with the file:

thing = YAML.load_file('login_as_user.yml')

http = thing['http_interactions']

alldoc = http[0]
response = alldoc['response']
body = response['body']
bodystring = body['string']

The string is the value of the body key, and if I print it in the body, it will return me this:

puts body

Body:

{"encoding"=>"ASCII-8BIT", "string"=>"{\n  \"loginresponse\": {\n    \"timeout\": \"43200\",\n    \"lastname\": \"sdsd\",\n    \"registered\": \"false\",\n    \"username\": \"sdsdsd\",\n    \"timezone\": \"America\\/New_York\",\n    \"firstname\": \"sdasdas \",\n    \"domainid\": \"ssssssssssss\",\n    \"type\": \"0\",\n    \"userid\": \"ssssssssssss1\",\n    \"sessionkey\": \"sssssssssss",\n    \"timezoneoffset\": \"-4.0\",\n    \"account\": \"sadsadsa\"\n  }\n}\n"}

But if I check the value of this string like this:

puts bodystring

It will be well formated:

{
  "loginresponse": {
  "timeout": "43200",
  "lastname": "wwd",
  "registered": "false",
  "username": "dddd",
  "timezone": "America\/New_York",
  "firstname": "dddd ",
  "domainid": "dddfdfdf",
  "type": "0",
  "userid": "dfsdfdsf",
  "sessionkey": "dsfdsfdsf",
  "timezoneoffset": "-4.0",
  "account": "dsfdsfdsfd"
 }
}

So the problem is in escaped symbols, and when I open the file and write it again, after working with the data, it has wrong formating.

I’d appreciate if somebody could help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:23:57+00:00Added an answer on June 14, 2026 at 5:23 am

    The body is just a string, but that string is the JSON encoding of a hash. To turn that JSON encoding into a Ruby hash, use the json gem:

    require 'json'
    body_hash = JSON.parse(bodystring)
    

    If you are in Rails, you’ve probably already got the json gem loaded and won’t need the require.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.