jq integration avatar
jq integration

Deprecated

Pricing

Pay per usage

Go to Store
jq integration

jq integration

Deprecated

Developed by

Zlata tretra

Zlata tretra

Maintained by Community

This Actor allows to manipulate datasets JSON data using jq manipulation tool.

0.0 (0)

Pricing

Pay per usage

0

Total users

2

Monthly users

1

Last modified

6 months ago

.actor/Dockerfile

# Specify the base Docker image. You can read more about
# the available images at https://docs.apify.com/sdk/js/docs/guides/docker-images
# You can also use any other image from Docker Hub.
FROM apify/actor-node:20
# Copy just package.json and package-lock.json
# to speed up the build using Docker layer cache.
COPY package*.json ./
# Install NPM packages, skip optional and development dependencies to
# keep the image small. Avoid logging too much and print the dependency
# tree for debugging
RUN npm --quiet set progress=false \
&& npm install --omit=dev --omit=optional \
&& echo "Installed NPM packages:" \
&& (npm list --omit=dev --all || true) \
&& echo "Node.js version:" \
&& node --version \
&& echo "NPM version:" \
&& npm --version \
&& rm -r ~/.npm
# Next, copy the remaining files and directories with the source code.
# Since we do this after NPM install, quick build will be really fast
# for most source file changes.
COPY . ./
# Run the image.
CMD npm start --silent

.actor/actor.json

{
"actorSpecification": 1,
"name": "jq-actor",
"title": "Transform dataset with jq JSON manipulation tool",
"description": "Allows passing jq command which manipulates given dataset and returns new one.",
"version": "0.0",
"input": "./input_schema.json",
"dockerfile": "./Dockerfile"
}

.actor/input_schema.json

{
"title": "Scrape data from a web page",
"description": "This is actor input schema",
"type": "object",
"schemaVersion": 1,
"properties": {
"filter": {
"title": "jq filter",
"type": "string",
"description": "jq filter as documented at https://jqlang.github.io/jq/manual/#basic-filters",
"default": ".",
"editor": "textfield"
},
"sort": {
"title": "Sort keys",
"type": "boolean",
"description": "Sort output keys alphabetically",
"default": false,
"editor": "checkbox"
},
"datasetId": {
"title": "Dataset ID",
"type": "string",
"description": "Platform dataset ID when Actor not set up as integration",
"editor": "textfield"
}
},
"required": [
"filter"
]
}

src/main.js

1import jq from 'node-jq';
2import { Actor } from 'apify';
3
4// The init() call configures the Actor for its environment. It's recommended to start every Actor with an init().
5await Actor.init();
6
7// Structure of input is defined in input_schema.json
8const { filter, sort, ...actorInput } = await Actor.getInput();
9
10
11const datasetId = actorInput.datasetId || actorInput.payload?.resource?.defaultDatasetId;
12
13
14const dataset = await Actor.openDataset(datasetId);
15
16// Use node-jq to filter and sort the input JSON
17const output = await jq.run(filter, dataset, { input: 'json', sort });
18
19
20await Actor.pushData(output);
21
22// Gracefully exit the Actor process. It's recommended to quit all Actors with an exit().
23await Actor.exit();

.dockerignore

# configurations
.idea
# crawlee and apify storage folders
apify_storage
crawlee_storage
storage
# installed files
node_modules
# git folder
.git

.gitignore

# This file tells Git which files shouldn't be added to source control
.DS_Store
.idea
dist
node_modules
apify_storage
storage/*
!storage/key_value_stores
storage/key_value_stores/*
!storage/key_value_stores/default
storage/key_value_stores/default/*
!storage/key_value_stores/default/INPUT.json
# Added by Apify CLI
storage
.venv

package.json

{
"name": "jq-actor",
"version": "0.0.1",
"type": "module",
"description": "Apify actor template for running JQ JSON manipulation tool.",
"engines": {
"node": ">=18.0.0"
},
"dependencies": {
"apify": "^3.1.10",
"axios": "^1.5.0",
"cheerio": "^1.0.0-rc.12",
"node-jq": "^6.0.1"
},
"scripts": {
"start": "node ./src/main.js"
},
"author": "Jan Turon",
"license": "ISC"
}