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 7826749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:33:29+00:00 2026-06-02T09:33:29+00:00

I have an output from an API that look like this… (its a string)

  • 0

I have an output from an API that look like this… (its a string)

[[2121212,212121,asd],[2323232,23232323,qasdasd]]

Its a string – not an array. I want to convert it to an array and then extract the first two elements in each array in the nested array to:

[2121212,212121],[2323232,23232323]

What’s the best way to do this ruby? I could use regexp and extract – but basically the string is already an array, however the class is a string.

I tried

array.push(response)

but that just put the string in to the array as one element. I guess what would be nice is a to_array method

  • 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-02T09:33:31+00:00Added an answer on June 2, 2026 at 9:33 am

    Assuming this is a JSON response (and if so, it is badly malformed and you should talk to the people that are responsible for this) you could write something like:

    require 'json'
    
    input= '[[2121212,212121,Asd],[2323232,23232323,qasdasd]]'
    input.gsub!(/([A-Za-z ]+)/,'"\1"')
    json = JSON.parse input
    output = json.map{|x| x[0...2]}
    p output
    

    this prints

    [[2121212, 212121], [2323232, 23232323]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to debug a segfault, and I have this output from gdb:
I have different php output in jQuery-based tabs. This output is formed from database
I have the following output from the uptime command: 14:48:51 up 23:34, 2 users,
I have an array of output from a database. I am wondering what the
I have a quite big XML output from an application. I need to process
I have the mytest.cc and mytest.h output from a mytest.proto file, but I can't
I'm having trouble finding/getting any logging output from a web service. I have a
I have a situation where I want to copy the output assembly from one
I have around 20000 files coming from the output of some program, and their
I am currently watching an XML file from log4j output. I have a custom

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.