13: parse raw json

how to parse raw json in requests

parse_raw_json
Author

Kennedy Mwavu

Published

July 29, 2024

Parse raw JSON

Sometimes you need to parse requests which have raw JSON in the body. ambiorix::parse_multipart() only works for ‘form-data’. That’s where webutils::parse_http() comes in.

This is a simple example revolving around how you can select columns and filter rows in the iris dataset when the request body is something like this:

{
    "cols": ["Sepal.Length", "Petal.Width", "Species"],
    "species": ["virginica", "setosa"]
}

Run API

  1. cd into the 13_parse_raw_json/ dir:

    cd 13_parse_raw_json/
  2. Fire up R and restore package dependencies:

    renv::restore()
  3. server.R is the entry point. Run this command in the terminal to start the API:

    Rscript server.R