# Partially typed schema

**URL:** <https://discuss.dgraph.io/t/partially-typed-schema/14591>\
**Category:** Dgraph\
**Tags:** schema\
**Created:** [June 14, 2021, 9:48pm UTC](https://discuss.dgraph.io/t/partially-typed-schema/14591 "2021-06-14T21:48:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![igrekun](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/igrekun/32/8545_2.png) [@igrekun](https://discuss.dgraph.io/u/igrekun)\
**Post date:** [June 14, 2021, 9:48pm UTC](https://discuss.dgraph.io/t/partially-typed-schema/14591/1 "2021-06-14T21:48:02Z")

</div>

I know in advance what structure I expect to receive for some parts of my data but one certain field can contain arbitrary JSON.

I want to be able to return the original JSON by following the node and run some aggregates over that JSON since I know names of certain fields.

What would be the best approach to handle that and what are my options?

Currently running

```auto
mutation = txn.create_mutation(set_obj=partial_data)
request = txn.create_request(mutations=[mutation], commit_now=True)
result = txn.do_request(request)

```

gives me awful lots of predicates and pollutes the namespace which is expected.

I want to receive the uid of inserted data and use it as a pointer from the strongly typed parts.

Any way to handle this without messing up my predicates and being able to run some limited queries?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [June 15, 2021, 12:56am UTC](https://discuss.dgraph.io/t/partially-typed-schema/14591/2 "2021-06-15T00:56:34Z")

</div>

After a mutation, you have to do a new query. Or use a method to return the UIDs created in that mutation. No mutation operation will return the inserted data.

---

<div class="post-metadata">

**Author:** ![igrekun](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/igrekun/32/8545_2.png) [@igrekun](https://discuss.dgraph.io/u/igrekun)\
**Post date:** [June 15, 2021, 10:14am UTC](https://discuss.dgraph.io/t/partially-typed-schema/14591/3 "2021-06-15T10:14:38Z")

</div>

Thanks for answering (:

Exactly. I’m using the UIDs created in that mutation to set edges to point at new data. Below is an example to illustrate what I’m trying to achieve.

```auto
type MyProduct {
  product.name
  product.props
}

product.name: string @index(term) .
product.props: uid .

```

A product always has a name string and some properties which are basically arbitrary JSON. I add “uid” key to props JSON so that I could identify the root node UID and set product.props to that value.

First thing - it pollutes predicate namespace with all the keys present in props JSON. Second - expand doesn’t work without a type hence I can’t retrieve the original props JSON.

I came up with a hack to just prepend all keys in props with prop. but that seems messy.

Is there any better way to store arbitrary JSONs for props and retrieving them back while having the ability to query over props?

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [June 23, 2021, 1:01am UTC](https://discuss.dgraph.io/t/partially-typed-schema/14591/4 "2021-06-23T01:01:47Z")

</div>

> [@igrekun](#):
>
> Is there any better way to store arbitrary JSONs for props and retrieving them back while having the ability to query over props?

Do you mean an JSON type? We don’t support JSON “blob” or something. Only the basic types like Int, String and so on.

---

<div class="post-metadata">

**Author:** ![igrekun](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/igrekun/32/8545_2.png) [@igrekun](https://discuss.dgraph.io/u/igrekun)\
**Post date:** [June 30, 2021, 8:16am UTC](https://discuss.dgraph.io/t/partially-typed-schema/14591/5 "2021-06-30T08:16:54Z")

</div>

Currently I went with storing that jsons as base64 strings and that’s ok. As for the original idea, consider the following data:

```auto
{'a': 1, 'b': 2.0, 'meta': {'cd': [1, 2, 3], 'ef': 0.5}}
{'a': 1, 'b': 2.0, 'meta': {'name': 'Andrew'}}
{'a': 1, 'b': 2.0, 'meta': {'location': {'lat': 1.27, 'lng': 0.44}}}

```

I can build schema for ‘a’ and ‘b’ because I know the types, as for the ‘meta’ - I don’t know what could it be, but the space of variations is finite.

Is it possible to save ‘meta’ in Dgraph and be able to query it, without getting all sorts of conflict with my own predicates?

The only hack that I came up with was to preprocess and append random salt to all keys inside ‘meta’.

---

<div class="post-metadata">

**Author:** ![MichelDiz](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/micheldiz/32/11873_2.png) [@MichelDiz](https://discuss.dgraph.io/u/MichelDiz)\
**Post date:** [June 30, 2021, 11:12am UTC](https://discuss.dgraph.io/t/partially-typed-schema/14591/6 "2021-06-30T11:12:38Z")

</div>

Try to use facets  
[https://dgraph.io/docs/mutations/json-mutation-format/#facets](https://dgraph.io/docs/mutations/json-mutation-format/#facets)
