Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Bugfix/jsonpath import in manual service (#6129)

Thomas Kaul7999ff973b8a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 088dd774bb..2ee1be4c13 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## Unreleased
+
+### Fixed
+
+- Fixed the import of `jsonpath` to support REST APIs (`JSON`) via the scraper configuration
+
## 2.226.0 - 2026-01-01
### Added
diff --git a/apps/api/src/helper/object.helper.spec.ts b/apps/api/src/helper/object.helper.spec.ts
index 4334903255..e1ec81b8fa 100644
--- a/apps/api/src/helper/object.helper.spec.ts
+++ b/apps/api/src/helper/object.helper.spec.ts
@@ -1,4 +1,24 @@
-import { redactAttributes } from './object.helper';
+import { query, redactAttributes } from './object.helper';
+
+describe('query', () => {
+ it('should get market price from stock API response', () => {
+ const object = {
+ currency: 'USD',
+ market: {
+ previousClose: 273.04,
+ price: 271.86
+ },
+ symbol: 'AAPL'
+ };
+
+ const result = query({
+ object,
+ pathExpression: '$.market.price'
+ })[0];
+
+ expect(result).toBe(271.86);
+ });
+});
describe('redactAttributes', () => {
it('should redact provided attributes', () => {
diff --git a/apps/api/src/helper/object.helper.ts b/apps/api/src/helper/object.helper.ts
index a5854e9d94..6bb6579d22 100644
--- a/apps/api/src/helper/object.helper.ts
+++ b/apps/api/src/helper/object.helper.ts
@@ -1,4 +1,5 @@
import { Big } from 'big.js';
+import jsonpath from 'jsonpath';
import { cloneDeep, isArray, isObject } from 'lodash';
export function hasNotDefinedValuesInObject(aObject: Object): boolean {
@@ -31,6 +32,16 @@ export function nullifyValuesInObjects<T>(aObjects: T[], keys: string[]): T[] {
});
}
+export function query({
+ object,
+ pathExpression
+}: {
+ object: object;
+ pathExpression: string;
+}) {
+ return jsonpath.query(object, pathExpression);
+}
+
export function redactAttributes({
isFirstRun = true,
object,
diff --git a/apps/api/src/services/data-provider/manual/manual.service.ts b/apps/api/src/services/data-provider/manual/manual.service.ts
index f18da49ab6..7392f0914b 100644
--- a/apps/api/src/services/data-provider/manual/manual.service.ts
+++ b/apps/api/src/services/data-provider/manual/manual.service.ts
@@ -1,3 +1,4 @@
+import { query } from '@ghostfolio/api/helper/object.helper';
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service';
import {
DataProviderInterface,
@@ -26,7 +27,6 @@ import { Injectable, Logger } from '@nestjs/common';
import { DataSource, SymbolProfile } from '@prisma/client';
import * as cheerio from 'cheerio';
import { addDays, format, isBefore } from 'date-fns';
-import * as jsonpath from 'jsonpath';
@Injectable()
export class ManualService implements DataProviderInterface {
@@ -286,9 +286,14 @@ export class ManualService implements DataProviderInterface {
let value: string;
if (response.headers.get('content-type')?.includes('application/json')) {
- const data = await response.json();
+ const object = await response.json();
- value = String(jsonpath.query(data, scraperConfiguration.selector)[0]);
+ value = String(
+ query({
+ object,
+ pathExpression: scraperConfiguration.selector
+ })[0]
+ );
} else {
const $ = cheerio.load(await response.text());
diff --git a/package-lock.json b/package-lock.json
index 9e897adc47..6512d2162a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -124,6 +124,7 @@
"@types/big.js": "6.2.2",
"@types/google-spreadsheet": "3.1.5",
"@types/jest": "30.0.0",
+ "@types/jsonpath": "0.2.4",
"@types/lodash": "4.17.20",
"@types/node": "22.15.17",
"@types/papaparse": "5.3.7",
@@ -12436,6 +12437,13 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/@types/jsonpath": {
+ "version": "0.2.4",
+ "resolved": "https://registry.npmjs.org/@types/jsonpath/-/jsonpath-0.2.4.tgz",
+ "integrity": "sha512-K3hxB8Blw0qgW6ExKgMbXQv2UPZBoE2GqLpVY+yr7nMD2Pq86lsuIzyAaiQ7eMqFL5B6di6pxSkogLJEyEHoGA==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/@types/jsonwebtoken": {
"version": "9.0.10",
"resolved": "https://registry.npmjs.org/@types/jsonwebtoken/-/jsonwebtoken-9.0.10.tgz",
diff --git a/package.json b/package.json
index 464a9a7cdd..59a455ae12 100644
--- a/package.json
+++ b/package.json
@@ -168,6 +168,7 @@
"@types/big.js": "6.2.2",
"@types/google-spreadsheet": "3.1.5",
"@types/jest": "30.0.0",
+ "@types/jsonpath": "0.2.4",
"@types/lodash": "4.17.20",
"@types/node": "22.15.17",
"@types/papaparse": "5.3.7",