jmespath / jmespath.jep

Proposals for extending the JMESPath Language.
8 stars 5 forks source link

Function proposal - parseJson() #8

Open tmccombs opened 4 years ago

tmccombs commented 4 years ago

Given a string containing embedded json, parse the json, and return the result.

This might be implemented something like:

registerFunction('parseJson', ([json]) => JSON.parse(json), [{types: [TYPE_STRING]}]);

Examples:

jmespath.search("\"true\"", "parseJson(@)")
// OUTPUTS: true

jmespath.search('"{\"a\":1, \"b\":\"c\"}"', "parseJson(@)")
// OUTPUTS {"a":1, "b":"c"}

The pattern of embedding json inside of strings in json is, unfortunately, somewhat common. For example, in AWS APIs.

springcomp commented 2 years ago

JSON Functions unofficial proposal.