MCPcopy
hub / github.com/cayleygraph/cayley / ParseJSONToQuadList

Function ParseJSONToQuadList

internal/http/write.go:35–60  ·  view source on GitHub ↗
(jsonBody []byte)

Source from the content-addressed store, hash-verified

33)
34
35func ParseJSONToQuadList(jsonBody []byte) (out []quad.Quad, _ error) {
36 var quads []struct {
37 Subject string `json:"subject"`
38 Predicate string `json:"predicate"`
39 Object string `json:"object"`
40 Label string `json:"label"`
41 }
42 err := json.Unmarshal(jsonBody, &quads)
43 if err != nil {
44 return nil, err
45 }
46 out = make([]quad.Quad, 0, len(quads))
47 for i, jq := range quads {
48 q := quad.Quad{
49 Subject: quad.StringToValue(jq.Subject),
50 Predicate: quad.StringToValue(jq.Predicate),
51 Object: quad.StringToValue(jq.Object),
52 Label: quad.StringToValue(jq.Label),
53 }
54 if !q.IsValid() {
55 return nil, fmt.Errorf("invalid quad at index %d. %s", i, q)
56 }
57 out = append(out, q)
58 }
59 return out, nil
60}
61
62const maxQuerySize = 1024 * 1024 // 1 MB
63func readLimit(r io.Reader) ([]byte, error) {

Callers 3

ServeV1WriteMethod · 0.85
ServeV1DeleteMethod · 0.85
TestParseJSONFunction · 0.85

Calls 2

ErrorfMethod · 0.65
UnmarshalMethod · 0.45

Tested by 1

TestParseJSONFunction · 0.68