Catman...et_json(3pm)

πŸ“¦
version 0.52 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu questing

πŸ’– Catmandu::Fix::get_json β€” the manual page, but make it make sense πŸ’–

okay bestie, you found the get_json page of the Perl docs (that's Catmandu::Fix::get_json, section 3pm), and honestly? it's a lil cutie. it grabs JSON from a URL and drops it right into your item. no cap. let's get into it. ✨


🌸 NAME 🌸

Catmandu::Fix::get_json β€” get JSON data from an URL as a fix function πŸ¦‹

πŸŽ€ SYNOPSIS πŸŽ€

        # fetches a hash or array
        get_json("http://example.com/json")

        # stores it in path.key
        get_json("http://example.com/json", path: path.key)

    # add URL query parameters or URL path from config
        get_json("http://example.com/", vars: config)

    # fill URL template fields from config
        get_json("http://example.com/{name}.json", vars: config)

        # get URL or URL template from a field
        get_json(field.name)

yes the indentation is exactly like that, we don't question the ancestors πŸ’…

✨ DESCRIPTION ✨

so this Catmandu::Fix gives you a method to fetch JSON data from an URL. that's it, that's the job. the response gets added as a new item, or dropped into a field of the current item β€” your choice, you're the main character here πŸ‘‘

πŸ”₯ OPTIONS πŸ”₯

first things first, bestie: the first argument has to be an URL, an URL template, or a field where to take an URL or URL template from. no first argument, no vibes. 😌

then you've got the extra options:

  • path β€” the field where the result JSON gets stored. if you don't give it, or you set it to the empty string "", then the whole item gets replaced by the fetched JSON response. and if the first argument is a field, that same field is used as path by default. cute, right? πŸŽ€
  • vars β€” the field to get URL template variables, URL query parameters, or an URL path expression from. this one is required if your first argument is an URL template. required required. not optional. 🫢

also, and this is important so don't scroll past it πŸ›‘

the fix function also supports the options dry, cache, timeout, agent, proxy, and wait β€” all as documented over in Catmandu::Importer::getJSON. go read that one if you need the deets, we're not re-explaining them here, that's their whole page πŸ“–

and now the part nobody likes: options client, headers, and warn are not supported. nope. not a thing. don't come for me, I don't make the rules 😭


that's the whole page, bestie, you ate it πŸ’…βœ¨

signing off: this was written for perl v5.36.0, dated 2022-12-10, and it lives in the User Contributed Perl Documentation. go forth and fetch that JSON. periodt. πŸ’–πŸŒˆπŸ¦‹

πŸ“¦ where this page comes from