[Tex/LaTex] API JSON in Latex

datatooljsonluatexurls

I want to know if it's possible to get data from a website using api json in a document .tex

I want to do this without luatex because the idea is compile online with the sharelatex website, that does't support luatex.

Best regards

Best Answer

I would recommend against trying to import data directly into LaTeX from a REST/JSON API. This would in any case require outside tools as LaTeX cannot open network connections. I'd suggest to use a language like Python or Ruby to query the API and to transform the JSON data into something that is easier to process with LaTeX.

A great tool for transforming JSON data is jq - I'm using it to trim down JSON data to the bits that I need in a document in combination with Curl to retrieve the data from a REST API.

Here is code using Curl, jq, and the API from above. It emits

\geo{37.4220352}%
     {-122.0841244}

which would be easy to parse in LaTeX by creating a command \geo.

#! /bin/sh

URL="http://216.58.210.138/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false"

curl -s "$URL" | jq -r '"
\\geo{\(.results[0].geometry.location.lat)}%
     {\(.results[0].geometry.location.lng)}
"'
Related Question