How to convert string to dig readable format rails?

Kunal Vashist

I using ruby on rails. I have a string that needs to converted to dig readable format

"search.user[0].user_id" convert this to [:search, :user,0, :user_id]

i am trying to use

"search.user[0].user_id".split('.').map(&:to_sym) which result to [:search, :user[0], :user_id]

How can i further split array index, string can position array user[0] at any position.

Vasfed

To parse your expression you can use:

"search.user[0].user_id".split(/]?\.|\[/).map{|k| k =~ /\A\d+\z/ && k.to_i || k.to_sym }
# => [:search, :user, 0, :user_id]

For a more generic approach also look at jsonpath (that parses more complex paths like $.store.book[*](category,author)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How do I convert API supplied date/time string into readable format?

分類Dev

How can I convert a JSON string to something readable?

分類Dev

Convert date from human readable format golang

分類Dev

convert escaped unicode sequence to human readable format

分類Dev

What is this date time format? How to convert it into a human readable output? Why it returns this output?

分類Dev

How to convert string data with variable format to datetime?

分類Dev

How to convert string into a date format in spark

分類Dev

How to convert oracle number type to string with format?

分類Dev

How to convert html entities to readable text?

分類Dev

Format JSON encoded string into more human readable in Silverstripe

分類Dev

Convert string into Array in rails

分類Dev

How to convert a string to byte array in bcd format in java?

分類Dev

How to convert a string to byte array in bcd format in java?

分類Dev

How to convert Date to String into the format yyyy-mm-dd in typescript

分類Dev

How to convert string format of time type field in DolphinDB c ++ API

分類Dev

How to format the given time string and convert to date/time object

分類Dev

String date format convert to date

分類Dev

Convert date format to string in Pandas

分類Dev

Convert string into an array with certain format

分類Dev

How to convert time date from JSON to human readable?

分類Dev

How can I convert date time format string used by C# to the format used by moment.js?

分類Dev

Convert sql to c#: Human readable string truncation based on string length

分類Dev

How to format numeric string?

分類Dev

How to convert date into given format?

分類Dev

How to convert animation to video format?

分類Dev

How to Convert This RGB format in Python

分類Dev

How to convert date format in JavaScript?

分類Dev

Parse UTC date string and convert to different format

分類Dev

Pandas - convert header name in tuple format to a string

Related 関連記事

  1. 1

    How do I convert API supplied date/time string into readable format?

  2. 2

    How can I convert a JSON string to something readable?

  3. 3

    Convert date from human readable format golang

  4. 4

    convert escaped unicode sequence to human readable format

  5. 5

    What is this date time format? How to convert it into a human readable output? Why it returns this output?

  6. 6

    How to convert string data with variable format to datetime?

  7. 7

    How to convert string into a date format in spark

  8. 8

    How to convert oracle number type to string with format?

  9. 9

    How to convert html entities to readable text?

  10. 10

    Format JSON encoded string into more human readable in Silverstripe

  11. 11

    Convert string into Array in rails

  12. 12

    How to convert a string to byte array in bcd format in java?

  13. 13

    How to convert a string to byte array in bcd format in java?

  14. 14

    How to convert Date to String into the format yyyy-mm-dd in typescript

  15. 15

    How to convert string format of time type field in DolphinDB c ++ API

  16. 16

    How to format the given time string and convert to date/time object

  17. 17

    String date format convert to date

  18. 18

    Convert date format to string in Pandas

  19. 19

    Convert string into an array with certain format

  20. 20

    How to convert time date from JSON to human readable?

  21. 21

    How can I convert date time format string used by C# to the format used by moment.js?

  22. 22

    Convert sql to c#: Human readable string truncation based on string length

  23. 23

    How to format numeric string?

  24. 24

    How to convert date into given format?

  25. 25

    How to convert animation to video format?

  26. 26

    How to Convert This RGB format in Python

  27. 27

    How to convert date format in JavaScript?

  28. 28

    Parse UTC date string and convert to different format

  29. 29

    Pandas - convert header name in tuple format to a string

ホットタグ

アーカイブ