Announcement

Collapse
No announcement yet.

HTTP profile - Twitter API brackets

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTTP profile - Twitter API brackets

    Hi All,
    I am just starting out with this plugin, looks very useful ! I'm pulling back some JSON from the twitter API and its received (can be seen in the BIG5 debug log) with square brackets enclosing all of it which seems to break the JSON expressions, eg :

    Code:
    [{
        "trends": [{
                "name": "#Beloved_Spring_Xiumin",
                "url": "http://twitter.com/search?q=%23Beloved_Spring_Xiumin",
                "promoted_content": null,
                "query": "%23Beloved_Spring_Xiumin",
                "tweet_volume": 403459
            },
            {
                "name": "#HAPPYXIUMINDAY",
                "url": "http://twitter.com/search?q=%23HAPPYXIUMINDAY",
                "promoted_content": null,
                "query": "%23HAPPYXIUMINDAY",
                "tweet_volume": 424678
            },
            {
                "name": "#ام_العمري_تنشادكم_بالله",
                "url": "http://twitter.com/search?q=%23%D8%A7%D9%85_%D8%A7%D9%84%D8%B9%D9%85%D8%B1%D9%8A_%D8%AA%D9%86%D8%B4%D8%A7%D8%AF%D9%83%D9%85_%D8%A8%D8%A7%D9%84%D9%84%D9%87",
                "promoted_content": null,
                "query": "%23%D8%A7%D9%85_%D8%A7%D9%84%D8%B9%D9%85%D8%B1%D9%8A_%D8%AA%D9%86%D8%B4%D8%A7%D8%AF%D9%83%D9%85_%D8%A8%D8%A7%D9%84%D9%84%D9%87",
                "tweet_volume": null
            }
        ],
        "as_of": "2020-03-25T18:04:12Z",
        "created_at": "2020-03-25T18:01:32Z",
        "locations": [{
            "name": "Worldwide",
            "woeid": 1
        }]
    }]

    When using ${ JSON(input, "trends[0].name") } in the expression sandbox it pulls back back the correct string when the "[" and "]" brackets are removed, but returns blank when they are left in place.

    Does anyone know what the correct way of stripping these brackets "[" and "]" at the beginning and end of the JSON response, or maybe receiving this data without the brackets in the first place ?


    Thanks,
    Mike

  • #2
    Big5 can handle that. See below.

    Comment


    • #3
      Group tags [ and ] are valid JSON syntax and very common.

      Comment


      • #4
        mikesnook

        ​​​​​​​Problem solved.

        Use this RegEx please

        ${ JSON(input, "[0].trends[0].name") }

        Comment


        • #5
          Originally posted by risquare View Post
          mikesnook

          Problem solved.

          Use this RegEx please

          ${ JSON(input, "[0].trends[0].name") }
          Awesome thank you, worked perfectly!

          Comment

          Working...
          X