Json Extract

Here is an instance of a single json doc:

{
  "GeneralInfo": {
    "Attributes": {
      "Name": "Test Name",
      "_id": "1996837697",
      "Description": "Test Description"
    },
  },
  "_recordId": "56v6t19xp9rni7",
  "_recordDate": "06-Feb-2015"
}

For simplicfaction, I’d like to extract _recordId and _id out of the document. Using JsonExtract Mapper UI i come up with:

<Mappings>
	<Mapping element="json_object">
		<Mapping element="GeneralInfo">
			<Mapping element="Attributes" outPort="0"
					xmlFields="../../{}_recordId;{}_id"
					cloverFields="_recordId;_id">
			</Mapping>
		</Mapping>
	</Mapping>
</Mappings>

However, the result on the port0 produces null value for first field (parent _recordId):
null , <_id value>

Can anyone tell me what i’m doing wrong? Looking at the documentation , xmlFields=“…/…/{}_recordId” should be valid way to access parent.

I was able to do exact same using JsonReader by manually typing:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Context xpath="/root/object" outPort="0">                                                             -->
  <Mapping cloverField="_recordId" xpath="_x005frecordId"/>
 
  <Context xpath="GeneralInfo/Attributes" outPort="1">
  	<Mapping cloverField="_id" xpath="_x005fid" />
    <Mapping cloverField="_recordId" xpath="../../_x005frecordId" />
  </Context>
</Context>

Hi,

The difference between JsonExtract and JsonReader is in the parser they use. The JsonExtract converts documents through SAX parser while JsonReader uses DOM parser. In a nutshell SAX parser goes through document from the top to the bottom and breaks his structure into the sequence of events that announces start and the end of each object, content of their properties etc. As the events do not carry references to the higher objects, JsonExtract can only recognize where one object starts and ends and so it can only combine attributes from the same object.
For instance in the document below “_id” and “_recordId” lies in different objects so JsonExtract cannot map both on the same edge. However JsonExtract can extract them separately and then by using other components merge them as it is done in the attached example. Both _id and _recordId are sent on separate edge with a sequence number. The sequence number is used to identify “_id” with “_recordId” and to join them together.

{
  "GeneralInfo": {
    "Attributes": {
      "Name": "Test Name",
      "_id": "1996837697",
      "Description": "Test Description"
    },
  },
  "_recordId": "56v6t19xp9rni7",
  "_recordDate": "06-Feb-2015"
}