Skip to content

Commit

Permalink
Merge branch '1.3-prerelease'
Browse files Browse the repository at this point in the history
  • Loading branch information
mtmorgan committed Apr 17, 2024
2 parents 92604d0 + d57dc5b commit 2c442a5
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 42 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/rhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# R-hub's generic GitHub Actions workflow file. It's canonical location is at
# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml
# You can update this file to a newer version using the rhub2 package:
#
# rhub::rhub_setup()
#
# It is unlikely that you need to modify this file manually.

name: R-hub
run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}"

on:
workflow_dispatch:
inputs:
config:
description: 'A comma separated list of R-hub platforms to use.'
type: string
default: 'linux,windows,macos'
name:
description: 'Run name. You can leave this empty now.'
type: string
id:
description: 'Unique ID. You can leave this empty now.'
type: string

jobs:

setup:
runs-on: ubuntu-latest
outputs:
containers: ${{ steps.rhub-setup.outputs.containers }}
platforms: ${{ steps.rhub-setup.outputs.platforms }}

steps:
# NO NEED TO CHECKOUT HERE
- uses: r-hub/actions/setup@v1
with:
config: ${{ github.event.inputs.config }}
id: rhub-setup

linux-containers:
needs: setup
if: ${{ needs.setup.outputs.containers != '[]' }}
runs-on: ubuntu-latest
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.containers) }}
container:
image: ${{ matrix.config.container }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/run-check@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}

other-platforms:
needs: setup
if: ${{ needs.setup.outputs.platforms != '[]' }}
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.label }}
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.setup.outputs.platforms) }}

steps:
- uses: r-hub/actions/checkout@v1
- uses: r-hub/actions/setup-r@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/platform-info@v1
with:
token: ${{ secrets.RHUB_TOKEN }}
job-config: ${{ matrix.config.job-config }}
- uses: r-hub/actions/setup-deps@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
- uses: r-hub/actions/run-check@v1
with:
job-config: ${{ matrix.config.job-config }}
token: ${{ secrets.RHUB_TOKEN }}
25 changes: 11 additions & 14 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rjsoncons
Title: 'C++' Header-Only 'jsoncons' Library for 'JSON' Queries
Version: 1.2.0.9900
Title: Query, Pivot, Patch, and Validate 'JSON' and 'NDJSON'
Version: 1.3.0
Authors@R: c(
person(
"Martin", "Morgan", role = c("aut", "cre"),
Expand All @@ -16,18 +16,15 @@ Authors@R: c(
email = "[email protected]",
comment = "jsoncons C++ library maintainer"
))
Description: The 'jsoncons'
<https://danielaparker.github.io/jsoncons/> 'C++' header-only
library constructs representations from a 'JSON' character vector,
and provides extensions for flexible queries and other operations
on 'JSON' objects. This package provides 'R' functions to query
(filter or transform) and pivot (convert from array-of-objects to
object-of-arrays, for easy import into 'R') 'JSON' or 'NDJSON'
strings or files using 'JSONpointer', 'JSONpath' or 'JMESpath'
expressions. The package also supports 'JSON' patch for
conveniently editing JSON documents, and 'JSON' schema for
validation. The 'jsoncons' library is easily linked to other
packages for direct access to 'C++' functionality.
Description: Functions to query (filter or transform), pivot (convert
from array-of-objects to object-of-arrays, for easy import as 'R'
data frame), search, patch (edit), and validate (against 'JSON
Schema') 'JSON' and 'NDJSON' strings, files, or URLs. Query and
pivot support 'JSONpointer', 'JSONpath' or 'JMESpath'
expressions. The implementation uses the 'jsoncons'
<https://danielaparker.github.io/jsoncons/> header-only library;
the library is easily linked to other packages for direct access
to 'C++' functionality not implemented here.
Imports: cli
Suggests: jsonlite, tibble, tinytest, BiocStyle, knitr, rmarkdown
LinkingTo: cpp11, cli
Expand Down
2 changes: 1 addition & 1 deletion R/patch.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ J_PATCH_OP <- c("add", "remove", "replace", "copy", "move", "test")
#' `jsonlite::toJSON()` argument `auto_unbox = TRUE` when `patch` is
#' an *R* object and any 'value' fields are JSON scalars; for more
#' complicated scenarios 'value' fields should be marked with
#' `jsonlite::unbox()` before being passsed to `j_patch_*()`.
#' `jsonlite::unbox()` before being passed to `j_patch_*()`.
#'
#' For `j_patch_op()` the `...` are additional arguments to the patch
#' operation, e.g., `path = ', `value = '.
Expand Down
4 changes: 2 additions & 2 deletions R/schema.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ do_j_schema <-
#' 'schema'.
#'
#' @param data JSON character vector, file, or URL defining document
#' to be valdiated. NDJSON data and schema are not supported.
#' to be validated. NDJSON data and schema are not supported.
#'
#' @param schema JSON character vector, file, or URL defining the
#' schema aganist which `data` will be validated.
#' schema against which `data` will be validated.
#'
#' @param ... passed to `jsonlite::toJSON` when `data` is not
#' character-valued.
Expand Down
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
![CRAN downloads](https://cranlogs.r-pkg.org/badges/last-month/rjsoncons)
<!-- badges: end -->

The [jsoncons][] C++ header-only library constructs representations
from a JSON character vector, and provides extensions for flexible
queries and other operations on JSON objects. This package provides
'R' functions to query (filter or transform) and pivot (convert from
array-of-objects to object-of-arrays, for easy import into 'R') 'JSON'
or 'NDJSON' strings or files using [JSONpath][], [JMESpath][], and
[JSONpointer][] expressions. The package also makes it easy to use C++
'jsoncons' in other *R* packages for direct access to 'C++'
functionality.

This package provides functions to query (filter or transform), pivot
(convert from array-of-objects to object-of-arrays, for easy import as
'R' data frame), search, patch (edit), and validate (against [JSON
Schema][]) 'JSON' and 'NDJSON' strings, files, or URLs. Query and
pivot support [JSONpointer][], [JSONpath][] or [JMESpath][]
expressions. The implementation uses the [jsoncons][] header-only
library; the library is easily linked to other packages for direct
access to 'C++' functionality not implemented here.

[JSON Schema]: https://json-schema.org
[JSONpath]: https://goessner.net/articles/JsonPath/
[JMESpath]: https://jmespath.org/
[JSONpointer]: https://datatracker.ietf.org/doc/html/rfc6901
Expand Down Expand Up @@ -48,9 +48,13 @@ library(rjsoncons)

The [introductory vignette][] outlines common use cases, including:

- Filtering large JSON documents to extract records of interest.
- Extracting deeply nested elements.
- Transforming data for more direct incorporation in *R* data structures.
- Filter large JSON or NDJSON documents to extract records or elements
of interest.
- Extract deeply nested elements.
- Transform data for more direct incorporation in *R* data structures.
- 'Patch' JSON strings programmatically, e.g., to update HTTP request
payloads.
- Validate JSON documents against JSON schemas

The [jsoncons][] C++ header-only library is a very useful starting
point for advanced JSON manipulation. The vignette outlines how
Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Release 1.2.0
# Release 1.3.0

- updates R functionality as described in NEWS.md
2 changes: 1 addition & 1 deletion man/patch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/schema.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions vignettes/a_rjsoncons.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Using 'jsoncons' in R"
title: "Transform and Validate JSON and NDJSON"
author:
- name: Martin Morgan
affiliation: Roswell Park Comprehensive Cancer Center, Buffalo, NY, US
Expand All @@ -8,7 +8,7 @@ author:
output:
BiocStyle::html_document
vignette: |
%\VignetteIndexEntry{Using the 'jsoncons' Library in R}
%\VignetteIndexEntry{Transform and Validate JSON and NDJSON}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand All @@ -21,11 +21,11 @@ knitr::opts_chunk$set(

# Introduction & installation

Use [rjsoncons][] for querying JSON, NDJSON, or R objects using
[JMESpath][], [JSONpath][], or [JSONpointer][]. [rjsoncons][] supports
[JSON patch][] for document editing, and [JSON schema][]
validation. Link to the package for direct access to additional
features in the '[jsoncons][]' C++ library.
Use [rjsoncons][] for querying, transforming, and searching JSON,
NDJSON, or R objects using [JMESpath][], [JSONpath][], or
[JSONpointer][]. [rjsoncons][] supports [JSON patch][] for document
editing, and [JSON schema][] validation. Link to the package for
direct access to additional features in the [jsoncons][] C++ library.

[jsoncons]: https://github.com/danielaparker/jsoncons/
[rjsoncons]: https://mtmorgan.github.io/rjsoncons/
Expand Down Expand Up @@ -395,7 +395,7 @@ j_schema_validate(op, schema, as = "tibble") |>
```

The validation indicates that the schema `evaluationPath`
'/items/oneOf' is not satisfied, becuases of the `error` 'No schema
'/items/oneOf' is not satisfied, because of the `error` 'No schema
[i.e., 'oneOf' elements] matched, ...'.

The 'details' column summarizes why each of the 3 elements of
Expand Down Expand Up @@ -615,6 +615,14 @@ the query as a JSON string, e.g., using the `fromJSON()` in the
[jsonlite][] package.

```{r jsonlite_fromJSON}
json <- '{
"locations": [
{"name": "Seattle", "state": "WA"},
{"name": "New York", "state": "NY"},
{"name": "Bellevue", "state": "WA"},
{"name": "Olympia", "state": "WA"}
]
}'
j_query(json, "locations[?state == 'WA']") |>
## `fromJSON()` simplifies list-of-objects to data.frame
jsonlite::fromJSON()
Expand Down

0 comments on commit 2c442a5

Please sign in to comment.