tencent cloud

All product documents
Tencent Cloud Observability Platform
jsonpath.get
Last updated: 2025-03-11 20:04:59
jsonpath.get
Last updated: 2025-03-11 20:04:59
jsonpath.get is used to get the value of the corresponding path from a JSON string.
get(json: string, path: string): string | number | boolean | object

Parameters

Parameter
Type
Description
json
string
JSON string.
path
string
Value path.

Return

Type
Description
string, number, boolean, or object.
The data obtained from the value.

Samples

Obtain the value for the given path:
import jsonpath from 'pts/jsonpath';

export default function () {
const json = JSON.stringify({
name: { first: 'Tom', last: 'Anderson' },
age: 37,
children: ['Sara', 'Alex', 'Jack'],
'fav.movie': 'Deer Hunter',
friends: [
{ first: 'Dale', last: 'Murphy', age: 44, nets: ['ig', 'fb', 'tw'] },
{ first: 'Roger', last: 'Craig', age: 68, nets: ['fb', 'tw'] },
{ first: 'Jane', last: 'Murphy', age: 47, nets: ['ig', 'tw'] },
]
});

console.log(jsonpath.get(json, 'name.last')); // Anderson
console.log(jsonpath.get(json, 'age')); // 37
console.log(jsonpath.get(json, 'children')); // Sara,Alex,Jack
console.log(jsonpath.get(json, 'children[*]')); // Sara,Alex,Jack
console.log(jsonpath.get(json, 'children.[0]')); // Sara
console.log(jsonpath.get(json, 'children[1:2]')); // Alex,Jack
console.log(jsonpath.get(json, 'friends[:].first')); // Dale,Roger,Jane
console.log(jsonpath.get(json, 'friends[1].last')); // Craig
console.log(jsonpath.get(json, 'friends[?(@.age > 45)].last')); // Craig,Murphy
console.log(jsonpath.get(json, 'friends[?(@.first =~ /D.*e/)].last')); // Murphy
}

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon