jsonpath

How to modify the value of a JsonNode recursively using Jackson

坚强是说给别人听的谎言 提交于 2019-12-11 05:07:09
问题 Requirements: I want to apply some functions on the inner values of the JsonNode . The functions can be different eg:- lowercasing some values or appending something to the values or replace the values with something. How can I achieve that using Jackson library? Note that the structure of the JSON data can be different which means I want to build a generic system which will accept some path expression which will basically decide where to change. I want to use functional programming style, so

How to find last item in a repeated structure in bigquery

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 03:57:24
问题 I have a nested repeated structure, the repeated structure is of variable length. For example, it could be a person object with a repeated structure that holds cities the person has lived in. I'd like to find the last item in that list say to find current city person lives in. Is there an easy way to do this, I tried looking around jsonpath functions but I'm not sure how to use it with "within". Any help please? 回答1: 1) You can use LAST and WITHIN SELECT FIRST(cell.value) within record , LAST

Is there a query language for JSON which allow access to parent node and has multiselect?

送分小仙女□ 提交于 2019-12-11 02:42:47
问题 There are many query languages for JSON, such as JMES Path and JSON Path, but none of the ones I've found interest me, e.g. JSON Path doesn't allow multiselect query (I can't return a list with different type element [car, plane, boat]) and JMES Path is really simpler compare to the JSON Path and allow the multiselect but doesn't allow the access to the parent node like .. or parent(@) or $(for the source). So I want a language which can do both, if it's possible a query language simple as

JSONPath Syntax when dot in key

跟風遠走 提交于 2019-12-10 18:20:56
问题 Please forgive me if I use the incorrect terminology, I am quite the novice. I have some simple JSON: { "properties": { "footer.navigationLinks": { "group": "layout" , "default": [ { "text": "Link a" , "href": "#" } ] } } I am trying to pinpoint "footer.navigationLinks" but I am having trouble with the dot in the key name. I am using http://jsonpath.com/ and when I enter $.properties['footer.navigationLinks'] I get 'No match'. If I change the key to "footernavigationLinks" it works but I

JSONPath expression for checking string in Apache Camel XML

旧时模样 提交于 2019-12-10 17:24:18
问题 Let's say I have a simple json file such as the following { "log": { "host": "blah", "severity": "INFO", "system": "1" } } I'm using Apache Camel, and it's Spring XML to process and route the json file. My routing code looks something like this: <route> <from uri="file:/TESTFOLDER/input"/> <choice> <when> <jsonpath>$.log?(@.severity == 'WARNING')</jsonpath> <to uri="smtp://(smtpinfo...not important)"/> </when> <otherwise> <to uri="file:/TESTFOLDER/output"/> </otherwise> </choice> </route> The

Using jsonPath looking for a string

谁说我不能喝 提交于 2019-12-10 16:08:25
问题 I'm trying to use jsonPath and the pick function to determine if a rule needs to run or not based on the current domain. A simplified version of what I'm doing is here: global { dataset shopscotchMerchants <- "https://s3.amazonaws.com/app-files/dev/merchantJson.json" cachable for 2 seconds } rule checkdataset is active { select when pageview ".*" setting () pre { merchantData = shopscotchMerchants.pick("$.merchants[?(@.merchant=='Telefora')]"); } emit <| console.log(merchantData); |> } The

Get keys in JSON

╄→гoц情女王★ 提交于 2019-12-10 13:38:00
问题 I get the following JSON result from an external system: { "key1": "val1", "key2": "val2", "key3": "val3" } Now I want to display all keys and all values by using JSONPath. So I am looking for something to get key1, key2 and key3 as a result. Additionally I would like to use the index of a property, e. g. $....[2].key to get "key3" etc. Is there a way to do something like this? 回答1: I found that the tilda ~ symbol is able to retrieve the keys of the values it's called upon. So for your

数据的处理

痴心易碎 提交于 2019-12-09 20:06:16
爬虫数据的提取 正则表达式 规则---不同语言不同,比如js中的正则表达式 转移字符.* Re模块 compile findall---返回列表 search match sub---替换---返回结果字符串 正则会在最后的字符串提取时起作用 jsonpath 属于js中的内容,并不完全与Python兼容,其中有些函数不能使用 jsonpath接收的是json.loads()后的结果,所以是一个字典或者列表。也就是说jsonpath接收的必须是Python的内置对象。 jsonpath返回的是一个列表 Python中运行js代码--两个模块--反爬时会用到 js2py,本质上将js代码翻译成Python代码 pyexecjs,已经停止更新了 数据的清洗 数据的一致性---单位是否统一 数据的完整性---出版社信息 数据的唯一性---数据去重 数据的准确性---判断数据是否正确 数据的清洗 时间格式 数据类型转换---str_to_float 字符串处理 爬虫数据存储 文件 首先打开文件 open(文件,打开方式) json 使用ensure_ascii=False保持中文的形式 csv 结构简单:列行数据分别以逗号和换行符来分割 使用便捷:可直接被pandas、numpy等数据处理模块或直接导入Excel中进行处理 数据库 mysql 使用线程 更稳定 回滚实现更优秀

JSON Get parent object from child object

不羁的心 提交于 2019-12-08 19:18:22
问题 How can I get discount value if brand_id=='983' . Sample JSON: { "prods": [ { "info": { "rate": 100 }, "grocery": [ { "brand": "A", "brand_id": "983" }, { "brand": "B", "brand_id": "253" } ], "discount": "20" } ] } What I have tried till now is $.prods[*].grocery[?(@.brand_id=='983')] This returns me list/array of matched objects. But I am not able to traverse back into the tree. Any help on this? 回答1: Indeed, JSONPath isn't very good at that, so I tackled this kind of problem with my own