Skip to content

A Web API to invoke methods on Jayway Jsonpath library.

License

Notifications You must be signed in to change notification settings

psumiya/json-path-api

Repository files navigation

Json Path API

A Web API that wraps https://github.com/json-path/JsonPath library calls.

tl;dr

Client/Browser → Amazon Route53 → Amazon API Gateway → AWS Lambda → Jayway JsonPath Library

Build and Deploy Commands

To build and deploy into your own AWS account, follow this:

# Build the zip file that contains the artifacts necessary for the Lambda (you need Docker for this to run successfully)
./gradlew clean buildZip

# Set S3 bucket and object where the zip will be uploaded
export STACK_NAME=json-path-api
# Use a bucket from your AWS account
export S3_BUCKET=<YOUR-S3-BUCKET-NAME-HERE>
export S3_KEY=lambdas/json-path

# Upload the built zip to S3
aws s3 cp build/distributions/json-path-api-1.0-SNAPSHOT.zip s3://$S3_BUCKET/$S3_KEY/JsonPathEvaluator.zip

# Create stack (one-time step) - this creates the Lambda function and the API Gateway endpoint (note it down)
sam deploy --s3-bucket $S3_BUCKET --stack-name $STACK_NAME --capabilities CAPABILITY_IAM --template-file cloudformation/template.yaml --parameter-overrides ParameterKey=LambdaCodeS3URI ParameterValue=s3://$S3_BUCKET/$S3_KEY/JsonPathEvaluator.zip

# (Optional) Update function after re-uploading a newly built zip
aws lambda update-function-code --function-name JsonPathEvaluator --s3-bucket $S3_BUCKET --s3-key $S3_KEY/JsonPathEvaluator.zip

# (Optional) Delete stack when you are done and do not need to retain the resources.
aws cloudformation delete-stack --stack-name $STACK_NAME

Test the API Endpoint

Replace the endpoint with the newly generated api in the below command and test.

export API_URL=<YOUR_API_URL_HERE>
curl $API_URL -H "Content-Type: application/json" -d \
'{
  "jsonToEvaluate" : "[{\"foo\" : \"foo1\",\"bar\" : \"bar1\"}{\"foo\" : \"foo2\"}]",
  "pathExpression" : "$[*].bar",
  "jsonPathOptions" : ["SUPPRESS_EXCEPTIONS","ALWAYS_RETURN_LIST"]
}'

You should see a successful result as shown below.

["bar1"]

If you intend to use a front-end, you may find this useful: https://github.com/psumiya/til/blob/main/http/options/cors.adoc

Here is a web application that uses a customized API endpoint as described above: https://sumiya.page/jpath.html

Lambda Runtime

  • Current Runtime: Java 21

  • Architecture: ARM64

In the past, I wrote about how the JRE for this project evolved from Java 11 to a custom Java 19 runtime here: https://sumiya.page/aws-lambda-custom-runtime-with-java-and-gradle.html

About

A Web API to invoke methods on Jayway Jsonpath library.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages