有没有办法用 JSON 指针选择一个数组成员作为键的值?所以对于这个 JSON 模式:
"links":[
{
"title": "Create",
"href": "/book",
"method": "POST",
"schema": {}
},
{
"title": "Get",
"href": "/book",
"method": "GET",
"schema": {}
}
]
Run Code Online (Sandbox Code Playgroud)
代替:
links/0/schema
Run Code Online (Sandbox Code Playgroud)
我希望能够做到:
links/{title=GET}/schema
Run Code Online (Sandbox Code Playgroud) 是否可以以这样的方式键入字符串数组,使得该数组只能是给定对象中的有效属性路径?类型定义应该适用于所有深度嵌套的对象。
例子:
const object1 = {
someProperty: true
};
const object2 = {
nestedObject: object1,
anotherProperty: 2
};
type PropertyPath<Type extends object> = [keyof Type, ...Array<string>]; // <-- this needs to be improved
// ----------------------------------------------------------------
let propertyPath1: PropertyPath<typeof object1>;
propertyPath1 = ["someProperty"]; // works
propertyPath1 = ["doesntExist"]; // should not work
let propertyPath2: PropertyPath<typeof object2>;
propertyPath2 = ["nestedObject", "someProperty"]; // works
propertyPath2 = ["nestedObject", "doesntExist"]; // should not work
propertyPath2 = ["doesntExist"]; // should not work
Run Code Online (Sandbox Code Playgroud)
我正在使用Jackson(版本 2.6+)来解析一些看起来像这样的丑陋的JSON:
{
"root" : {
"dynamic123" : "Some value"
}
}
Run Code Online (Sandbox Code Playgroud)
dynamic123不幸的是,直到运行时才知道该属性的名称,并且可能会不时不同。我想要实现的是使用JsonPointer来获取 value "Some value"。JsonPointer使用此处描述的类似XPath的语法。
// { "root" : { "dynamic123" : "Some value" } }
ObjectNode json = mapper.createObjectNode();
json.set("root", json.objectNode().put("dynamic123", "Some value"));
// Some basics
JsonNode document = json.at(""); // Ok, the entire document
JsonNode missing = json.at("/missing"); // MissingNode (as expected)
JsonNode root = json.at("/root"); // Ok -> { dynamic123 : "Some …Run Code Online (Sandbox Code Playgroud) Jackson提供了JsonPointer。但是,我想做类似https://github.com/json-path/JsonPath可以提供的事情。我如何在 JsonPointer 中描述这一点?:
$.store.book[?(@.price < 10)]
Run Code Online (Sandbox Code Playgroud)
有些人认为:
JsonPointer p = JsonPointer.compile("/store/book[????]");
Run Code Online (Sandbox Code Playgroud) 我需要将JSON指针定义的JSON(或JavaScript对象)中的位置映射到JSON文本文件中的位置{line,column}.是否有任何现有的JavaScript库可以做到这一点?编写这段代码会有点单调乏味......
例如,如果我有一个JSON文件(文本):
{
"foo": [
{
"bar": 1
}
]
}
Run Code Online (Sandbox Code Playgroud)
然后给出JSON指针,/foo/0/bar我需要得到{line: 4, column: 7}结果.
如果此JSON文件中存储了等效的JSON值:
{"foo":[{"bar":1}]}
Run Code Online (Sandbox Code Playgroud)
那么相同的JSON指针的结果应该是{line: 1, column: 10}.
我正在尝试使用 JSON Schema 验证 JSON 文件,以查找“损坏的引用”的情况。基本上我的文件由项目和组组成,每个项目都属于由 groups 属性键引用的单个组,如下所示:
{
"items": {
"banana": {
"name": "Banana",
"group": "fruits"
},
"apple": {
"name": "Apple",
"group": "fruits"
},
"carrot": {
"name": "Carrot",
"group": "vegetables"
},
"potato": {
"name": "Potato",
"group": "vegetables"
},
"cheese": {
"name": "Cheese",
"group": "dairy"
}
},
"groups": {
"fruits": {
"name": "Fruits"
},
"vegetables": {
"name": "Vegetables"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,项目cheese被认为是无效的,因为对象中没有dairy属性groups。我尝试使用以下模式验证这一点:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"title": "Food",
"id": "food",
"type": "object",
"properties": {
"items": …Run Code Online (Sandbox Code Playgroud) Argo CD 显示 linkerd(由 Helm 安装)中的两个项目不同步。preserveUnknownFields: false这些警告是由该部分中的可选选项引起的spec:
Trafficsplits.split.smi-spec.io

serviceprofiles.linkerd.io
但我无法弄清楚如何忽略清单ignoreDifferences中使用的差异Application。json路径/spec/preserveUnknownFields不起作用。是因为左侧版本中不存在字段preserveUnknownFields吗?
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: linkerd
namespace: argocd
spec:
destination:
namespace: linkerd
server: https://kubernetes.default.svc
project: default
source:
chart: linkerd2
repoURL: https://helm.linkerd.io/stable
targetRevision: 2.10.1
syncPolicy:
automated: {}
ignoreDifferences:
- group: apiextensions.k8s.io/v1
name: trafficsplits.split.smi-spec.io
kind: CustomResourceDefinition
jsonPointers:
- /spec/preserveUnknownFields
- group: apiextensions.k8s.io/v1
name: trafficsplits.split.smi-spec.io
kind: CustomResourceDefinition
jsonPointers:
- /spec/preserveUnknownFields
Run Code Online (Sandbox Code Playgroud) 我目前有
openapi: 3.1.0
info:
title: My API
version:
$ref: package.json#/version
description: |
practically the same content as README.md
Run Code Online (Sandbox Code Playgroud)
有没有办法使用 JSON 指针嵌入文本而不是 JSON 对象?类似的东西
openapi: 3.1.0
info:
title: My API
version:
$ref: package.json#/version
description: |
$ref: README.md
Run Code Online (Sandbox Code Playgroud) jsonpointer ×9
json ×4
jackson ×2
ajv ×1
argocd ×1
enums ×1
java ×1
javascript ×1
json-patch ×1
jsonpath ×1
jsonschema ×1
kubernetes ×1
linkerd ×1
openapi ×1
recursion ×1
reflection ×1
source-maps ×1
types ×1
typescript ×1
yaml ×1