Add a "view in JSON" local task How can I add a Preview in JSON local task?  

My link is exactly the same of entity.node.canonical, but I have to add a query string (?_format=json). I know how to add the local task, but I don't know how to append the query string to the URL.
You need to configure URL options in links.task.yml file. See Url::fromUri for details.

your_module.export:
  title: Export
  route_name: entity.node.canonical
  options:
    query: {_format: json}
  base_route: entity.node.canonical