Skip to main content
Question

JSON dynamically name columns related to value position

  • April 18, 2016
  • 5 replies
  • 74 views

Forum|alt.badge.img

I would like to organise data from a JSON file. The column headers I require are stored as comma separated string in the column column (Timestamp,Value,Quality Code,Absolute Value,AV Quality Code) and the associated related values are stored as a comma separated string in the data column (["2016-03-17T12:00:00.000+01:00",0,130,null,null]).

I need the set up to be dynamic as the data and columns will change with different parameters supplied as JSON.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

5 replies

takashi
Celebrity
  • April 18, 2016

Hi @heatha_featha, I suppose that you need to create these attributes from the two comma-separated values.

  • `Timestamp' has value `"2016-03-17T12:00:00.000+01:00"'
  • `Value' has value `0'
  • `Quality Code' has value `130'
  • `Absolute Value' has value `null'
  • `AV Quality Code' has value `null'

If I understand your requirement correctly, this workflow might help you. The MultiAttributeSplitter is a custom transformer published in the FME Hub (ex FME Store).

0684Q00000ArKlhQAF.png

Alternatively a PythonCaller with this script creates those attributes more efficiently.

def extractAttributes(feature):
    names = feature.getAttribute('column').split(',')
    values = feature.getAttribute('data').split(',')
    for name, value in zip(names, values):
        feature.setAttribute(name, value)

A TclCaller with this script does the same too.

proc extractAttributes {} {
    set names [split [FME_GetAttribute "column"] {,}]
    set values [split [FME_GetAttribute "data"] {,}]
    foreach name $names value $values {
        FME_SetAttribute $name $value
    }
}

Forum|alt.badge.img

Hi @heatha_featha, I suppose that you need to create these attributes from the two comma-separated values.

  • `Timestamp' has value `"2016-03-17T12:00:00.000+01:00"'
  • `Value' has value `0'
  • `Quality Code' has value `130'
  • `Absolute Value' has value `null'
  • `AV Quality Code' has value `null'

If I understand your requirement correctly, this workflow might help you. The MultiAttributeSplitter is a custom transformer published in the FME Hub (ex FME Store).

0684Q00000ArKlhQAF.png

Alternatively a PythonCaller with this script creates those attributes more efficiently.

def extractAttributes(feature):
    names = feature.getAttribute('column').split(',')
    values = feature.getAttribute('data').split(',')
    for name, value in zip(names, values):
        feature.setAttribute(name, value)

A TclCaller with this script does the same too.

proc extractAttributes {} {
    set names [split [FME_GetAttribute "column"] {,}]
    set values [split [FME_GetAttribute "data"] {,}]
    foreach name $names value $values {
        FME_SetAttribute $name $value
    }
}

Hi @takashi,' thank you for your quick response. 

The MultiAttributeSplitter (useful tool) and the ListExploder work well. However when I inspect the output of the BulkAttributeRenamer a feature count is listed, however no data is shown, and the data column has simply been renamed to @value(column).

I would have expected that the intention of the regular expression in the BulkAttributeRenamer is to create 5 new columns, each containing the associated data values? 

Can you please explain what is happening through the BulkAttributeRenamer and Agrregator in a bit more detail?


takashi
Celebrity
  • April 20, 2016

Hi @takashi,' thank you for your quick response.

The MultiAttributeSplitter (useful tool) and the ListExploder work well. However when I inspect the output of the BulkAttributeRenamer a feature count is listed, however no data is shown, and the data column has simply been renamed to @value(column).

I would have expected that the intention of the regular expression in the BulkAttributeRenamer is to create 5 new columns, each containing the associated data values?

Can you please explain what is happening through the BulkAttributeRenamer and Agrregator in a bit more detail?

Hi @heatha_featha, I think you entered '@Value(column)' as a string literal into the field. In this case, this parameter should be set to the value of 'column' attribute. Try setting it using the menu command, like this.


Forum|alt.badge.img

Hi @heatha_featha, I suppose that you need to create these attributes from the two comma-separated values.

  • `Timestamp' has value `"2016-03-17T12:00:00.000+01:00"'
  • `Value' has value `0'
  • `Quality Code' has value `130'
  • `Absolute Value' has value `null'
  • `AV Quality Code' has value `null'

If I understand your requirement correctly, this workflow might help you. The MultiAttributeSplitter is a custom transformer published in the FME Hub (ex FME Store).

0684Q00000ArKlhQAF.png

Alternatively a PythonCaller with this script creates those attributes more efficiently.

def extractAttributes(feature):
    names = feature.getAttribute('column').split(',')
    values = feature.getAttribute('data').split(',')
    for name, value in zip(names, values):
        feature.setAttribute(name, value)

A TclCaller with this script does the same too.

proc extractAttributes {} {
    set names [split [FME_GetAttribute "column"] {,}]
    set values [split [FME_GetAttribute "data"] {,}]
    foreach name $names value $values {
        FME_SetAttribute $name $value
    }
}

Hi @takashi,', I am using FME 2015 and it doesn't have the additional Mode parameter. Can you please confirm that you are using the standard BulkAttributeRenamer transformer (from 2016?)? 


takashi
Celebrity
  • April 20, 2016

Hi @takashi,', I am using FME 2015 and it doesn't have the additional Mode parameter. Can you please confirm that you are using the standard BulkAttributeRenamer transformer (from 2016?)?

Yes, the screenshot is from FME 2016.0, but you don't need to mind the Mode setting in this case. The behavior of the BulkAttributeRenamer in FME 2015 is the same as the Mode "Rename" in 2016.