How can i decode this data?

I am making text button that shows google search result.

But i don’t know how to shorten this data.
This is what i want to get.
“estimation using stepwise regression was only significantly better than linear regression for dataset. LEL-G2. No statistical difference otherwise.”
(It’s in items snippet)

This is my code.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, text)
    local key = "It's secret"
	local response = httpService:GetAsync("https://www.googleapis.com/customsearch/v1?key=" .. key .."&cx=017576662512468239146:omuauf_lfve&q="..text.."&callback=hndlr")

	local data = response
	
	print(data)
end)

And this is the result.

  19:09:33.800  // API callback
hndlr({
  "kind": "customsearch#search",
  "url": {
    "type": "application/json",
    "template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
  },
  "queries": {
    "request": [
      {
        "title": "Google Custom Search - lel",
        "totalResults": "30600000",
        "searchTerms": "lel",
        "count": 10,
        "startIndex": 1,
        "inputEncoding": "utf8",
        "outputEncoding": "utf8",
        "safe": "off",
        "cx": "017576662512468239146:omuauf_lfve"
      }
    ],
    "nextPage": [
      {
        "title": "Google Custom Search - lel",
        "totalResults": "30600000",
        "searchTerms": "lel",
        "count": 10,
        "startIndex": 11,
        "inputEncoding": "utf8",
        "outputEncoding": "utf8",
        "safe": "off",
        "cx": "017576662512468239146:omuauf_lfve"
      }
    ]
  },
  "context": {
    "title": "CS Curriculum",
    "facets": [
      [
        {
          "anchor": "Lectures",
          "label": "lectures",
          "label_with_op": "more:lectures"
        }
      ],
      [
        {
          "anchor": "Assignments",
          "label": "assignments",
          "label_with_op": "more:assignments"
        }
      ],
      [
        {
          "anchor": "Reference",
          "label": "reference",
          "label_with_op": "more:reference"
        }
      ]
    ]
  },
  "searchInformation": {
    "searchTime": 0.353113,
    "formattedSearchTime": "0.35",
    "totalResults": "30600000",
    "formattedTotalResults": "30,600,000"
  },
  "items": [
    {
      "kind": "customsearch#result",
      "title": "S2 S3 S4",
      "htmlTitle": "S2 S3 S4",
      "link": "https://www.cs.auckland.ac.nz/~dazh001/SLR/RQ1_Tables.pdf",
      "displayLink": "www.cs.auckland.ac.nz",
      "snippet": "estimation using stepwise regression was only significantly better than linear regression for dataset. LEL-G2. No statistical difference otherwise.",
      "htmlSnippet": "estimation using stepwise regression was only significantly better than linear regression for dataset. \u003cb\u003eLEL\u003c/b\u003e-G2. No statistical difference otherwise.",
      "cacheId": "KYBPPD8KRLgJ",
      "formattedUrl": "https://www.cs.auckland.ac.nz/~dazh001/SLR/RQ1_Tables.pdf",
      "htmlFormattedUrl": "https://www.cs.auckland.ac.nz/~dazh001/SLR/RQ1_Tables.pdf",
      "pagemap": {
        "cse_thumbnail": [
          {
            "src": "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSRAtXeoC2jizu0QmCx4wB6S5YtVt6H0tdJ-4GyPAIDdSmq1ZaPzr5zMV2p",
            "width": "267",
            "height": "189"
          }
        ],
        "metatags": [
          {
            "moddate": "D:20120430190943+12'00'",
            "creator": "Microsoft® Word 2010",
            "creationdate": "D:20120430190943+12'00'",
            "author": "dazh001",
            "producer": "Microsoft® Word 2010"
          }
        ],
        "cse_image": [
          {
            "src": "x-raw-image:///c5c114b1798b61d3bd7a6cb8f479d7984f54b71dfbfc69c9be75f9f8ec9fa45c"
          }
        ]
      },
      "mime": "application/pdf",
      "fileFormat": "PDF/Adobe Acrobat"
    },
    {
      "kind": "customsearch#result",
      "title": "Untitled - CS @ Columbia",
      "htmlTitle": "Untitled - CS @ Columbia",
      "link": "http://www.cs.columbia.edu/~cs4252/pdf/lectures/2022-09-22-Thurs.pdf",
      "displayLink": "www.cs.columbia.edu",
      "snippet": "Sep 22, 2022 ... Goal: algs, libi's that hold for any finite lel. Halving Algorithm. (H.A.). • Let CONSIST be the subset of e consisting of.",
      "htmlSnippet": "Sep 22, 2022 \u003cb\u003e...\u003c/b\u003e Goal: algs, libi's that hold for any finite \u003cb\u003elel\u003c/b\u003e. Halving Algorithm. (H.A.). • Let CONSIST be the subset of e consisting of.",
      "cacheId": "zr7Bu2twEc0J",
      "formattedUrl": "www.cs.columbia.edu/~cs4252/pdf/lectures/2022-09-22-Thurs.pdf",
      "htmlFormattedUrl": "www.cs.columbia.edu/~cs4252/pdf/lectures/2022-09-22-Thurs.pdf",
      "pagemap": {
        "cse_thumbnail": [
          {
            "src": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSVVywt--LsyBWnROcmtas4iz0e7mrVq0WBt9lVYYf8cmTjrw5UyYuJ-54",
            "width": "196",
            "height": "257"
          }
        ],
        "metatags": [
          {
            "moddate": "Thu Sep 22 13:57:43 2022",
            "creationdate": "Thu Sep 22 13:57:43 2022",
            "producer": "iOS Version 15.5 (Build 19F77) Quartz PDFContext"
          }
        ],
        "cse_image": [
          {
            "src": "x-raw-image:///b2144792a2e5400663fcc54a767402f8137f6e69be07c8e61b22957c2263cda4"
          }
        ]
      },
      "mime": "application/pdf",
      "fileFormat": "PDF/Adobe Acrobat",
      "labels": [
        {
          "name": "lectures",
          "displayName": "Lectures",
          "label_with_op": "more:lectures"
        }
      ]
    },
    {
      "kind": "customsearch#result",
      "title": "Coq.ZArith.Zwf - cs.Princeton",
      "htmlTitle": "Coq.ZArith.Zwf - cs.Princeton",
      "link": "https://www.cs.princeton.edu/courses/archive/fall07/cos595/stdlib/html/index_definition_L.html",
      "displayLink": "www.cs.princeton.edu",
      "snippet": "Global Index · (7984 entries) ; Axiom Index · (401 entries) ; Lemma Index · (5228 entries) ; Constructor Index · (292 entries) ; Inductive Index · (184 entries).",
      "htmlSnippet": "Global Index · (7984 entries) ; Axiom Index · (401 entries) ; Lemma Index · (5228 entries) ; Constructor Index · (292 entries) ; Inductive Index · (184 entries).",
      "cacheId": "c_ZmDarCRVcJ",
      "formattedUrl": "https://www.cs.princeton.edu/courses/archive/.../index_definition_L.html",
      "htmlFormattedUrl": "https://www.cs.princeton.edu/courses/archive/.../index_definition_L.html"
    },
    {
      "kind": "customsearch#result",
      "title": "Index - Yale FLINT Group",
      "htmlTitle": "Index - Yale FLINT Group",
      "link": "http://flint.cs.yale.edu/cs428/coq/library/index_global_L.html",
      "displayLink": "flint.cs.yale.edu",
      "snippet": "lel [definition, in Coq.Lists.MonoList] lel [definition, in Coq.Lists.List] lelistA [inductive, in Coq.Sorting.Sorting] lelistA_inv [lemma, in Coq.Sorting.",
      "htmlSnippet": "\u003cb\u003elel\u003c/b\u003e [definition, in Coq.Lists.MonoList] \u003cb\u003elel\u003c/b\u003e [definition, in Coq.Lists.List] lelistA [inductive, in Coq.Sorting.Sorting] lelistA_inv [lemma, in Coq.Sorting.",
      "cacheId": "XnXxtMRNHoQJ",
      "formattedUrl": "flint.cs.yale.edu/cs428/coq/library/index_global_L.html",
      "htmlFormattedUrl": "flint.cs.yale.edu/cs428/coq/library/index_global_L.html"
    },
    {
      "kind": "customsearch#result",
      "title": "cс 2004 IEEE. Personal use of this material is permitted. However ...",
      "htmlTitle": "cс 2004 IEEE. Personal use of this material is permitted. However ...",
      "link": "http://www.cs.cmu.edu/afs/cs/academic/class/15745-s07/www/papers/cgo04-ILP.pdf",
      "displayLink": "www.cs.cmu.edu",
      "snippet": "lel Instruction Computing (EPIC) architecture where the compiler is solely responsible for extracting and managing instruction-level parallelism.",
      "htmlSnippet": "\u003cb\u003elel\u003c/b\u003e Instruction Computing (EPIC) architecture where the compiler is solely responsible for extracting and managing instruction-level parallelism.",
      "formattedUrl": "www.cs.cmu.edu/afs/cs/academic/class/15745-s07/www/.../cgo04-ILP.pdf",
      "htmlFormattedUrl": "www.cs.cmu.edu/afs/cs/academic/class/15745-s07/www/.../cgo04-ILP.pdf",
      "pagemap": {
        "cse_thumbnail": [
          {
            "src": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRtDCWENN_zPtyt5D1u4K0mVR2TuhygqMXdbu3n0t9binM5ZPSuOwrGW_fN",
            "width": "197",
            "height": "255"
          }
        ],
        "metatags": [
          {
            "moddate": "D:20040805133744+02'00'",
            "creationdate": "D:20040126105904",
            "creator": "dvips(k) 5.92b Copyright 2002 Radical Eye Software",
            "producer": "Acrobat Distiller 4.05 for Windows",
            "title": "cgo04-final.dvi"
          }
        ],
        "cse_image": [
          {
            "src": "x-raw-image:///c60d5de81e14d916f1c18ecd36b3e00bb62d4b22476330f1964db630295d64ed"
          }
        ]
      },
      "mime": "application/pdf",
      "fileFormat": "PDF/Adobe Acrobat"
    },
    {
      "kind": "customsearch#result",
      "title": "CoCheck: Checkpointing and Process Migration for ... - CS@Cornell",
      "htmlTitle": "CoCheck: Checkpointing and Process Migration for ... - CS@Cornell",
      "link": "http://www.cs.cornell.edu/courses/cs717/2001fa/papers/IPPS96.ps",
      "displayLink": "www.cs.cornell.edu",
      "snippet": "lel applications. In difference to existing systems CoCheck. rather sits on top of the message passing library than inside.",
      "htmlSnippet": "\u003cb\u003elel\u003c/b\u003e applications. In difference to existing systems CoCheck. rather sits on top of the message passing library than inside.",
      "cacheId": "Ck9yBbsEx4wJ",
      "formattedUrl": "www.cs.cornell.edu/courses/cs717/2001fa/papers/IPPS96.ps",
      "htmlFormattedUrl": "www.cs.cornell.edu/courses/cs717/2001fa/papers/IPPS96.ps",
      "pagemap": {
        "metatags": [
          {
            "creator": "dvips 5.518 Copyright 1986, 1993 Radical Eye Software",
            "creationdate": "Thu Jan 11 17:59:17 1996",
            "producer": "GNU Ghostscript 7.07",
            "title": "ieee.dvi"
          }
        ]
      },
      "mime": "application/postscript",
      "fileFormat": "Adobe PostScript"
    },
    {
      "kind": "customsearch#result",
      "title": "Untitled - CS @ Columbia",
      "htmlTitle": "Untitled - CS @ Columbia",
      "link": "http://www.cs.columbia.edu/~cs4252/pdf/lectures/2022-09-08-Thurs.pdf",
      "displayLink": "www.cs.columbia.edu",
      "snippet": "Sep 8, 2022 ... •Examples: disj., conje, s-term DNF K-CNFs. LoLTES. CNF, K-ONFS s-clause CNF,. LTFs (linear threshold functions).",
      "htmlSnippet": "Sep 8, 2022 \u003cb\u003e...\u003c/b\u003e •Examples: disj., conje, s-term DNF K-CNFs. LoLTES. CNF, K-ONFS s-clause CNF,. LTFs (linear threshold functions).",
      "cacheId": "DwNEDogG0TYJ",
      "formattedUrl": "www.cs.columbia.edu/~cs4252/pdf/lectures/2022-09-08-Thurs.pdf",
      "htmlFormattedUrl": "www.cs.columbia.edu/~cs4252/pdf/lectures/2022-09-08-Thurs.pdf",
      "pagemap": {
        "cse_thumbnail": [
          {
            "src": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSVqi6h3_3amSahdLodRh5l1KiQHzTcnPomyW3UkfneZTgg4xkx2czpvdo",
            "width": "196",
            "height": "257"
          }
        ],
        "metatags": [
          {
            "moddate": "Thu Sep  8 13:59:29 2022",
            "creationdate": "Thu Sep  8 13:59:29 2022",
            "producer": "iOS Version 15.5 (Build 19F77) Quartz PDFContext"
          }
        ],
        "cse_image": [
          {
            "src": "x-raw-image:///6eb8d601038f712903fe431b1f2a63c8c9fd3f8b5bdeadd6ae1d8c626db7e880"
          }
        ]
      },
      "mime": "application/pdf",
      "fileFormat": "PDF/Adobe Acrobat",
      "labels": [
        {
          "name": "lectures",
          "displayName": "Lectures",
          "label_with_op": "more:lectures"
        }
      ]
    },
    {
      "kind": "customsearch#result",
      "title": "Chapter 9. Related Work - UT Computer Science",
      "htmlTitle": "Chapter 9. Related Work - UT Computer Science",
      "link": "https://www.cs.utexas.edu/ftp/techreports/tr93-28.dir/12-RelWk.ps.Z",
      "displayLink": "www.cs.utexas.edu",
      "snippet": "lel computation that includes non-fixed firing conditions. The model also per-. mits proof of determinacy and useful theorems on computation terminations.",
      "htmlSnippet": "\u003cb\u003elel\u003c/b\u003e computation that includes non-fixed firing conditions. The model also per-. mits proof of determinacy and useful theorems on computation terminations.",
      "cacheId": "dpAmqGgeJOcJ",
      "formattedUrl": "https://www.cs.utexas.edu/ftp/techreports/tr93-28.dir/12-RelWk.ps.Z",
      "htmlFormattedUrl": "https://www.cs.utexas.edu/ftp/techreports/tr93-28.dir/12-RelWk.ps.Z",
      "pagemap": {
        "metatags": [
          {
            "creator": "(FrameMaker: LaserWriter 8 8.1.1)",
            "creationdate": "(1:51 PM Tuesday, November 9, 1993)",
            "author": "(spiff)",
            "producer": "GNU Ghostscript 7.07",
            "title": "(RelatedWork)"
          }
        ]
      },
      "mime": "application/postscript",
      "fileFormat": "Adobe PostScript"
    },
    {
      "kind": "customsearch#result",
      "title": "Untitled - CS @ Columbia",
      "htmlTitle": "Untitled - CS @ Columbia",
      "link": "http://www.cs.columbia.edu/~cs4252/pdf/lectures/2022-09-27-Tues.pdf",
      "displayLink": "www.cs.columbia.edu",
      "snippet": "Sep 27, 2022 ... UCOIM (e) = loga lel. P4. Page 5. (Need 2\" concepts in e to shatter set of Kpts.) 1e/=2\". So VCO IM (e) in. Connection to OLMB learning!",
      "htmlSnippet": "Sep 27, 2022 \u003cb\u003e...\u003c/b\u003e UCOIM (e) = loga \u003cb\u003elel\u003c/b\u003e. P4. Page 5. (Need 2" concepts in e to shatter set of Kpts.) 1e/=2". So VCO IM (e) in. Connection to OLMB learning!",
      "cacheId": "rnI3n_lSTEwJ",
      "formattedUrl": "www.cs.columbia.edu/~cs4252/pdf/lectures/2022-09-27-Tues.pdf",
      "htmlFormattedUrl": "www.cs.columbia.edu/~cs4252/pdf/lectures/2022-09-27-Tues.pdf",
      "pagemap": {
        "cse_thumbnail": [
          {
            "src": "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQoaJVAgQ1NUsMQaYJthVD6JCPnF4k8gKFQy7H-Z85COXPp_3Zhte4VWkk",
            "width": "196",
            "height": "257"
          }
        ],
        "metatags": [
          {
            "moddate": "Tue Sep 27 13:56:32 2022",
            "creationdate": "Tue Sep 27 13:56:32 2022",
            "producer": "iOS Version 15.5 (Build 19F77) Quartz PDFContext"
          }
        ],
        "cse_image": [
          {
            "src": "x-raw-image:///a253ef41d4818fb6f95cd4ad1580e1e48b749c85334e2c3314a2f8d00c31fd9c"
          }
        ]
      },
      "mime": "application/pdf",
      "fileFormat": "PDF/Adobe Acrobat",
      "labels": [
        {
          "name": "lectures",
          "displayName": "Lectures",
          "label_with_op": "more:lectures"
        }
      ]
    },
    {
      "kind": "customsearch#result",
      "title": "API: dragdrop DDProxy.js (YUI Library) - CSE-IITB",
      "htmlTitle": "API: dragdrop DDProxy.js (YUI Library) - CSE-IITB",
      "link": "https://www.cse.iitb.ac.in/~cs387/yui/docs/DDProxy.js.html",
      "displayLink": "www.cse.iitb.ac.in",
      "snippet": "Dom; this.logger.log(this.id + \" endDrag\"); var lel = this.getEl(); var del = this.getDragEl(); // Show the drag frame briefly so we can get its position ...",
      "htmlSnippet": "Dom; this.logger.log(this.id + " endDrag"); var \u003cb\u003elel\u003c/b\u003e = this.getEl(); var del = this.getDragEl(); // Show the drag frame briefly so we can get its position ...",
      "cacheId": "-oCB8_QL_I4J",
      "formattedUrl": "https://www.cse.iitb.ac.in/~cs387/yui/docs/DDProxy.js.html",
      "htmlFormattedUrl": "https://www.cse.iitb.ac.in/~cs387/yui/docs/DDProxy.js.html"
    }
  ]
}
);  -  Server - SearchRequestServer:23
1 Like

You need to use JSONDecode
response = game:GetService("HttpService"):JSONDecode(response)

4 Likes

This can only be JSONDecoded if you remove specific strings that cause the JSONDecode function to error, I was able to locate those strings using the json parser website and write functions to automatically get rid of them:

--Removes the "hndlr" part of the string that causes JSON decode issues
function removeHndlr(response: string): string 
	local text = response:split("hndlr(")[2] 
	return text:sub(1, text:len()-2) 
end
--Removes the "htmlSnippet" property of the data that causes issues because of unescaped characters.
function removeHtmlSnippet(response: string): string 
	local lines = response:split("\n")
	local result = ""
	for _, line in pairs(lines) do 
		if line:find("htmlSnippet") then continue end 
		result ..= line.."\n"
	end
	return result 
end
--Applies the 2 rules above
function prepareForDecode(response: string): string 
	return removeHtmlSnippet(removeHndlr(response))
end

local data = httpService:JSONDecode(prepareForDecode(response))
local snippet = data.items[1].snippet 
print(snippet) --your text
2 Likes

Thanks very much.
This is exactly what i want.
It works good now :smiley:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.